Title: [293807] trunk/Source/WTF/wtf/text/StringView.cpp
Revision
293807
Author
cdu...@apple.com
Date
2022-05-04 17:44:40 -0700 (Wed, 04 May 2022)

Log Message

Optimize / simplify slow case in StringView::convertASCIILowercaseAtom() https://bugs.webkit.org/show_bug.cgi?id=240082

Reviewed by Darin Adler.

Optimize / simplify slow case in StringView::convertASCIILowercaseAtom() where the input string
is not already lowercase. We now call `makeAtomString(lowercase(input))` which simplifies the
code a lot and is actually more efficient because makeAtomString() has an optimization that
avoids a StringImpl allocation when the string is relatively small (< 64 characters) and is
already part of the AtomStringTable already.

I validated the implementation by running it in a loop with the String "BODY" and got a
~35% speedup.

* Source/WTF/wtf/text/StringView.cpp:
(WTF::convertASCIILowercaseAtom):

Canonical link: https://commits.webkit.org/250280@main

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/text/StringView.cpp (293806 => 293807)


--- trunk/Source/WTF/wtf/text/StringView.cpp	2022-05-05 00:20:52 UTC (rev 293806)
+++ trunk/Source/WTF/wtf/text/StringView.cpp	2022-05-05 00:44:40 UTC (rev 293807)
@@ -253,16 +253,8 @@
 static AtomString convertASCIILowercaseAtom(const CharacterType* input, unsigned length)
 {
     for (unsigned i = 0; i < length; ++i) {
-        if (UNLIKELY(isASCIIUpper(input[i]))) {
-            CharacterType* characters;
-            auto result = String::createUninitialized(length, characters);
-            StringImpl::copyCharacters(characters, input, i);
-            for (; i < length; ++i)
-                characters[i] = toASCIILower(input[i]);
-            // FIXME: This is inefficient. Ideally, we wouldn't have to allocate a String/StringImpl if the
-            // string is already in the AtomStringTable.
-            return AtomString(result);
-        }
+        if (UNLIKELY(isASCIIUpper(input[i])))
+            return makeAtomString(lowercase(StringView { input, length }));
     }
     // Fast path when the StringView is already all lowercase.
     return AtomString(input, length);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to