2010-12-31 Patrick Gansterer <paroga@webkit.org>
authorparoga@webkit.org <paroga@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Dec 2010 12:43:34 +0000 (12:43 +0000)
committerparoga@webkit.org <paroga@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 31 Dec 2010 12:43:34 +0000 (12:43 +0000)
        Reviewed by Darin Adler.

        Add a fast case for ASCII strings in HashAndUTF8CharactersTranslator::equal
        https://bugs.webkit.org/show_bug.cgi?id=50517

        This change shows about 2% performance win on the xml-parser benchmark.

        * wtf/text/AtomicString.cpp:
        (WTF::HashAndUTF8CharactersTranslator::equal):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@74829 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/wtf/text/AtomicString.cpp

index b8a6a92..bd49e93 100644 (file)
@@ -1,3 +1,15 @@
+2010-12-31  Patrick Gansterer  <paroga@webkit.org>
+
+        Reviewed by Darin Adler.
+
+        Add a fast case for ASCII strings in HashAndUTF8CharactersTranslator::equal
+        https://bugs.webkit.org/show_bug.cgi?id=50517
+
+        This change shows about 2% performance win on the xml-parser benchmark.
+
+        * wtf/text/AtomicString.cpp:
+        (WTF::HashAndUTF8CharactersTranslator::equal):
+
 2010-12-30  Patrick Gansterer  <paroga@webkit.org>
 
         Reviewed by Ariya Hidayat.
index acbcd34..93ad21d 100644 (file)
@@ -225,7 +225,22 @@ struct HashAndUTF8CharactersTranslator {
 
     static bool equal(StringImpl* const& string, const HashAndUTF8Characters& buffer)
     {
-        return equalUTF16WithUTF8(string->characters(), string->characters() + string->length(), buffer.characters, buffer.characters + buffer.length);
+        if (buffer.utf16Length != string->length())
+            return false;
+
+        const UChar* stringCharacters = string->characters();
+
+        // If buffer contains only ASCII characters UTF-8 and UTF16 length are the same.
+        if (buffer.utf16Length != buffer.length)
+            return equalUTF16WithUTF8(stringCharacters, stringCharacters + string->length(), buffer.characters, buffer.characters + buffer.length);
+
+        for (unsigned i = 0; i < buffer.length; ++i) {
+            ASSERT(isASCII(buffer.characters[i]));
+            if (stringCharacters[i] != buffer.characters[i])
+                return false;
+        }
+
+        return true;
     }
 
     static void translate(StringImpl*& location, const HashAndUTF8Characters& buffer, unsigned hash)