Title: [293821] trunk/Source
Revision
293821
Author
cdu...@apple.com
Date
2022-05-04 22:48:33 -0700 (Wed, 04 May 2022)

Log Message

Optimize some convertToASCIIUppercase() call sites
https://bugs.webkit.org/show_bug.cgi?id=240095

Reviewed by Darin Adler.

Optimize some convertToASCIIUppercase() call sites. Also rename lowercase(StringView)
/ uppercase(StringView) to asASCIILowercase(StringView) / asASCIIUppercase(StringView)
for clarity, given that they only work with ASCII case.

* Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::handleForWebPageProxy):
(WebKit::WebAutomationSession::handleForWebFrameID):
* Source/WTF/wtf/text/StringConcatenate.h:
(WTF::asASCIILowercase):
(WTF::asASCIIUppercase):
(WTF::lowercase): Deleted.
(WTF::uppercase): Deleted.
* Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:
(WebCore::hostName):
* Source/WebCore/css/ContainerQueryParser.cpp:
(WebCore::consumeFeatureName):
* Source/WebCore/css/MediaQueryExpression.cpp:
(WebCore::MediaQueryExpression::serialize const):
* Source/WebCore/css/parser/CSSParserSelector.cpp:
(WebCore::CSSParserSelector::parsePseudoElementSelector):
(WebCore::CSSParserSelector::parsePseudoClassSelector):
* Source/WebCore/dom/TextDecoder.cpp:
(WebCore::TextDecoder::encoding const):
* Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp:
(WebCore::languageIdentifier):
* Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp:
(WebCore::extractLocaleFromDictionaryFileName):
(WebCore::canHyphenate):
(WebCore::lastHyphenLocation):
* Source/WebCore/xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::getAllResponseHeaders const):

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

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/text/StringConcatenate.h (293820 => 293821)


--- trunk/Source/WTF/wtf/text/StringConcatenate.h	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WTF/wtf/text/StringConcatenate.h	2022-05-05 05:48:33 UTC (rev 293821)
@@ -377,12 +377,12 @@
     StringView string;
 };
 
-inline ASCIICaseConverter lowercase(StringView stringView)
+inline ASCIICaseConverter asASCIILowercase(StringView stringView)
 {
     return { StringView::CaseConvertType::Lower, stringView };
 }
 
-inline ASCIICaseConverter uppercase(StringView stringView)
+inline ASCIICaseConverter asASCIIUppercase(StringView stringView)
 {
     return { StringView::CaseConvertType::Upper, stringView };
 }
@@ -544,9 +544,9 @@
 using WTF::makeString;
 using WTF::makeStringByInserting;
 using WTF::pad;
-using WTF::lowercase;
+using WTF::asASCIILowercase;
+using WTF::asASCIIUppercase;
 using WTF::tryMakeString;
 using WTF::tryMakeAtomString;
-using WTF::uppercase;
 
 #include <wtf/text/StringOperators.h>

Modified: trunk/Source/WTF/wtf/text/StringView.cpp (293820 => 293821)


--- trunk/Source/WTF/wtf/text/StringView.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WTF/wtf/text/StringView.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -254,7 +254,7 @@
 {
     for (unsigned i = 0; i < length; ++i) {
         if (UNLIKELY(isASCIIUpper(input[i])))
-            return makeAtomString(lowercase(StringView { input, length }));
+            return makeAtomString(asASCIILowercase(StringView { input, length }));
     }
     // Fast path when the StringView is already all lowercase.
     return AtomString(input, length);

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (293820 => 293821)


--- trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -77,10 +77,9 @@
 static String hostName(const URL& url, bool secure)
 {
     ASSERT(url.protocolIs("wss") == secure);
-    String host = url.host().convertToASCIILowercase();
     if (url.port() && ((!secure && url.port().value() != 80) || (secure && url.port().value() != 443)))
-        return makeString(host, ':', url.port().value());
-    return host;
+        return makeString(asASCIILowercase(url.host()), ':', url.port().value());
+    return url.host().convertToASCIILowercase();
 }
 
 static constexpr size_t maxInputSampleSize = 128;

Modified: trunk/Source/WebCore/css/ContainerQueryParser.cpp (293820 => 293821)


--- trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/css/ContainerQueryParser.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -171,9 +171,7 @@
 {
     if (range.peek().type() != IdentToken)
         return nullAtom();
-    // FIXME: This is a bit inefficient. Ideally, we'd convert to lowercase as part of converting the
-    // StringView to an AtomString.
-    return AtomString { range.consumeIncludingWhitespace().value().convertToASCIILowercase() };
+    return range.consumeIncludingWhitespace().value().convertToASCIILowercaseAtom();
 }
 
 std::optional<CQ::SizeFeature> ContainerQueryParser::consumePlainSizeFeature(CSSParserTokenRange& range)

Modified: trunk/Source/WebCore/css/MediaQueryExpression.cpp (293820 => 293821)


--- trunk/Source/WebCore/css/MediaQueryExpression.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/css/MediaQueryExpression.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -274,7 +274,7 @@
 String MediaQueryExpression::serialize() const
 {
     if (m_serializationCache.isNull())
-        m_serializationCache = makeString('(', m_mediaFeature.convertToASCIILowercase(), m_value ? ": " : "", m_value ? m_value->cssText() : emptyString(), ')');
+        m_serializationCache = makeString('(', asASCIILowercase(m_mediaFeature), m_value ? ": " : "", m_value ? m_value->cssText() : emptyString(), ')');
     return m_serializationCache;
 }
 

Modified: trunk/Source/WebCore/css/parser/CSSParserSelector.cpp (293820 => 293821)


--- trunk/Source/WebCore/css/parser/CSSParserSelector.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/css/parser/CSSParserSelector.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -60,11 +60,9 @@
     selector->m_selector->setMatch(CSSSelector::PseudoElement);
     selector->m_selector->setPseudoElementType(pseudoType);
     AtomString name;
-    if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed) {
-        // FIXME: This is a bit inefficient. Ideally, we'd convert to lowercase as part of converting the
-        // StringView to an AtomString.
-        name = AtomString { pseudoTypeString.convertToASCIILowercase() };
-    } else {
+    if (pseudoType != CSSSelector::PseudoElementWebKitCustomLegacyPrefixed)
+        name = pseudoTypeString.convertToASCIILowercaseAtom();
+    else {
         if (equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-input-placeholder"_s))
             name = "placeholder"_s;
         else if (equalLettersIgnoringASCIICase(pseudoTypeString, "-webkit-file-upload-button"_s))
@@ -71,9 +69,7 @@
             name = "file-selector-button"_s;
         else {
             ASSERT_NOT_REACHED();
-            // FIXME: This is a bit inefficient. Ideally, we'd convert to lowercase as part of converting the
-            // StringView to an AtomString.
-            name = AtomString { pseudoTypeString.convertToASCIILowercase() };
+            name = pseudoTypeString.convertToASCIILowercaseAtom();
         }
     }
     selector->m_selector->setValue(name);
@@ -93,9 +89,7 @@
         auto selector = makeUnique<CSSParserSelector>();
         selector->m_selector->setMatch(CSSSelector::PseudoElement);
         selector->m_selector->setPseudoElementType(pseudoType.compatibilityPseudoElement);
-        // FIXME: This is a bit inefficient. Ideally, we'd convert to lowercase as part of converting the
-        // StringView to an AtomString.
-        selector->m_selector->setValue(AtomString { pseudoTypeString.convertToASCIILowercase() });
+        selector->m_selector->setValue(pseudoTypeString.convertToASCIILowercaseAtom());
         return selector;
     }
     return nullptr;

Modified: trunk/Source/WebCore/dom/TextDecoder.cpp (293820 => 293821)


--- trunk/Source/WebCore/dom/TextDecoder.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/dom/TextDecoder.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -81,7 +81,7 @@
 
 String TextDecoder::encoding() const
 {
-    return String::fromLatin1(m_textEncoding.name()).convertToASCIILowercase();
+    return makeString(asASCIILowercase(m_textEncoding.name()));
 }
 
 }

Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (293820 => 293821)


--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -659,11 +659,12 @@
     if (languageCode.isEmpty())
         return languageCode;
 
-    String lowercaseLanguageCode = languageCode.convertToASCIILowercase();
-
+    String lowercaseLanguageCode;
     // Need 2U here to disambiguate String::operator[] from operator(NSString*, int)[] in a production build.
-    if (lowercaseLanguageCode.length() >= 3 && (lowercaseLanguageCode[2U] == '_' || lowercaseLanguageCode[2U] == '-'))
-        lowercaseLanguageCode = lowercaseLanguageCode.left(2);
+    if (languageCode.length() >= 3 && (languageCode[2U] == '_' || languageCode[2U] == '-'))
+        lowercaseLanguageCode = StringView(languageCode).left(2).convertToASCIILowercase();
+    else
+        lowercaseLanguageCode = languageCode.convertToASCIILowercase();
 
     return lowercaseLanguageCode;
 }

Modified: trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp (293820 => 293821)


--- trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -60,8 +60,7 @@
     // so we strip everything except the locale.
     constexpr int prefixLength = 5;
     constexpr int suffixLength = 4;
-    // FIXME: Ideally, we'd do the conversion to lowercase as part of converting to AtomString.
-    return AtomString { StringView(fileName).substring(prefixLength, fileName.length() - prefixLength - suffixLength).convertToASCIILowercase() };
+    return StringView(fileName).substring(prefixLength, fileName.length() - prefixLength - suffixLength).convertToASCIILowercaseAtom();
 }
 
 static void scanDirectoryForDictionaries(const char* directoryPath, HashMap<AtomString, Vector<String>>& availableLocales)
@@ -176,7 +175,7 @@
         return false;
     if (availableLocales().contains(localeIdentifier))
         return true;
-    return availableLocales().contains(AtomString(localeIdentifier.string().convertToASCIILowercase()));
+    return availableLocales().contains(localeIdentifier.convertToASCIILowercase());
 }
 
 class HyphenationDictionary : public RefCounted<HyphenationDictionary> {

Modified: trunk/Source/WebCore/xml/XMLHttpRequest.cpp (293820 => 293821)


--- trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebCore/xml/XMLHttpRequest.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -845,7 +845,7 @@
 
         StringBuilder stringBuilder;
         for (auto& header : headers)
-            stringBuilder.append(lowercase(header.first), ": ", header.second, "\r\n");
+            stringBuilder.append(asASCIILowercase(header.first), ": ", header.second, "\r\n");
 
         m_allResponseHeaders = stringBuilder.toString();
     }

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (293820 => 293821)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2022-05-05 04:56:56 UTC (rev 293820)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2022-05-05 05:48:33 UTC (rev 293821)
@@ -190,7 +190,7 @@
     if (iter != m_webPageHandleMap.end())
         return iter->value;
 
-    String handle = makeString("page-"_s, createVersion4UUIDString().convertToASCIIUppercase());
+    String handle = makeString("page-"_s, asASCIIUppercase(createVersion4UUIDString()));
 
     auto firstAddResult = m_webPageHandleMap.add(webPageProxy.identifier(), handle);
     RELEASE_ASSERT(firstAddResult.isNewEntry);
@@ -239,7 +239,7 @@
     if (iter != m_webFrameHandleMap.end())
         return iter->value;
 
-    String handle = makeString("frame-"_s, createVersion4UUIDString().convertToASCIIUppercase());
+    String handle = makeString("frame-"_s, asASCIIUppercase(createVersion4UUIDString()));
 
     auto firstAddResult = m_webFrameHandleMap.add(*frameID, handle);
     RELEASE_ASSERT(firstAddResult.isNewEntry);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to