From 733f6b770fcd7c2e5577bfb1fc738dc6ae5c3920 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Sat, 25 May 2019 18:02:40 +0300 Subject: use memcmp for nsIAtom Equals to improve performance xpcom/ds issue #1113 Use memcmp and not slower string Equals in nsHtml5Portability::localEqualsBuffer --- xpcom/ds/nsAtomTable.cpp | 8 +------- xpcom/ds/nsIAtom.idl | 10 ++++++++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 4c93625ae..c2e77e31f 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -325,13 +325,7 @@ AtomTableMatchKey(const PLDHashEntryHdr* aEntry, const void* aKey) nsDependentAtomString(he->mAtom)) == 0; } - uint32_t length = he->mAtom->GetLength(); - if (length != k->mLength) { - return false; - } - - return memcmp(he->mAtom->GetUTF16String(), - k->mUTF16String, length * sizeof(char16_t)) == 0; + return he->mAtom->Equals(k->mUTF16String, k->mLength); } static void diff --git a/xpcom/ds/nsIAtom.idl b/xpcom/ds/nsIAtom.idl index 6e8602c42..ce4cff485 100644 --- a/xpcom/ds/nsIAtom.idl +++ b/xpcom/ds/nsIAtom.idl @@ -37,9 +37,15 @@ interface nsIAtom : nsISupports size_t SizeOfIncludingThis(in MallocSizeOf aMallocSizeOf); %{C++ - // note this is NOT virtual so this won't muck with the vtable! + // note these are NOT virtual so they won't muck with the vtable! + inline bool Equals(char16ptr_t aString, uint32_t aLength) const + { + return mLength == aLength && + memcmp(mString, aString, mLength * sizeof(char16_t)) == 0; + } + inline bool Equals(const nsAString& aString) const { - return aString.Equals(nsDependentString(mString, mLength)); + return Equals(aString.BeginReading(), aString.Length()); } inline bool IsStaticAtom() const { -- cgit v1.2.3 From bf1e5431f05532e457306c0944b3812ab6ea39f2 Mon Sep 17 00:00:00 2001 From: win7-7 Date: Sat, 25 May 2019 18:04:02 +0300 Subject: use memcmp for nsIAtom Equals to improve performance parser/html issue MoonchildProductions#1113 Use memcmp and not slower string Equals in nsHtml5Portability::localEqualsBuffer --- parser/html/nsHtml5Portability.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parser/html/nsHtml5Portability.cpp b/parser/html/nsHtml5Portability.cpp index 36c7e758a..0a7c6f845 100644 --- a/parser/html/nsHtml5Portability.cpp +++ b/parser/html/nsHtml5Portability.cpp @@ -91,7 +91,7 @@ nsHtml5Portability::releaseString(nsString* str) bool nsHtml5Portability::localEqualsBuffer(nsIAtom* local, char16_t* buf, int32_t offset, int32_t length) { - return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length)); + return local->Equals(buf + offset, length); } bool -- cgit v1.2.3