Title: [293056] trunk
Revision
293056
Author
cdu...@apple.com
Date
2022-04-19 19:32:43 -0700 (Tue, 19 Apr 2022)

Log Message

Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral
https://bugs.webkit.org/show_bug.cgi?id=239500

Reviewed by Darin Adler.

Source/WebCore:

* Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
(WebCore::IDBServer::SQLiteIDBBackingStore::encodeDatabaseName):
* display/css/DisplayTextBox.cpp:
(WebCore::Display::TextBox::debugDescription const):
* dom/Node.cpp:
(WebCore::Node::showNode const):
* dom/Text.cpp:
(WebCore::appendTextRepresentation):
* editing/EditingStyle.cpp:
(WebCore::StyleChange::extractTextStyles):
* editing/Editor.cpp:
(WebCore::Editor::selectedText const):
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::appendQuotedURLAttributeValue):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::takeResults):
* html/URLDecomposition.cpp:
(WebCore::URLDecomposition::setSearch):
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::outputLayoutBox):
* loader/FormSubmission.cpp:
(WebCore::appendMailtoPostFormDataToURL):
* rendering/LegacyInlineTextBox.cpp:
(WebCore::LegacyInlineTextBox::outputLineBox const):
* rendering/RenderObject.cpp:
(WebCore::RenderObject::outputRenderObject const):
* xml/XSLTProcessor.cpp:
(WebCore::transformTextStringToXHTMLDocumentString):

Source/WTF:

Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral.
replaceWithLiteral() was encouraging people not to use ASCIILiteral and the ""_s suffix and calling
replace() with an ASCIILiteral would result in less efficient code, which goes against the idea of
ASCIILiteral.

To address this, String::replaceWithLiteral() is removed. Now, callers can call String::replace()
with an ASCIILiteral instead and it will result in code that is as efficient. I have verified that
this change is perf-neutral on Speedometer on both Apple Silicon and Intel.

* wtf/text/WTFString.h:
(WTF::String::replace):
(WTF::String::replaceWithLiteral): Deleted.

Tools:

* TestWebKitAPI/Tests/WTF/WTFString.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/inspector/agents/InspectorAuditAgent.cpp (293055 => 293056)


--- trunk/Source/_javascript_Core/inspector/agents/InspectorAuditAgent.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/_javascript_Core/inspector/agents/InspectorAuditAgent.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -92,7 +92,7 @@
     if (injectedScript.hasNoValue())
         return makeUnexpected(errorString);
 
-    auto functionString = makeString("(function(WebInspectorAudit) { \"use strict\"; return eval(`(", String { test }.replace('`', "\\`"), ")`)(WebInspectorAudit); })");
+    auto functionString = makeString("(function(WebInspectorAudit) { \"use strict\"; return eval(`(", String { test }.replace('`', "\\`"_s), ")`)(WebInspectorAudit); })");
 
     InjectedScript::ExecuteOptions options;
     options.objectGroup = "audit"_s;

Modified: trunk/Source/WTF/ChangeLog (293055 => 293056)


--- trunk/Source/WTF/ChangeLog	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WTF/ChangeLog	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1,5 +1,25 @@
 2022-04-19  Chris Dumez  <cdu...@apple.com>
 
+        Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral
+        https://bugs.webkit.org/show_bug.cgi?id=239500
+
+        Reviewed by Darin Adler.
+
+        Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral.
+        replaceWithLiteral() was encouraging people not to use ASCIILiteral and the ""_s suffix and calling
+        replace() with an ASCIILiteral would result in less efficient code, which goes against the idea of
+        ASCIILiteral.
+
+        To address this, String::replaceWithLiteral() is removed. Now, callers can call String::replace()
+        with an ASCIILiteral instead and it will result in code that is as efficient. I have verified that
+        this change is perf-neutral on Speedometer on both Apple Silicon and Intel.
+
+        * wtf/text/WTFString.h:
+        (WTF::String::replace):
+        (WTF::String::replaceWithLiteral): Deleted.
+
+2022-04-19  Chris Dumez  <cdu...@apple.com>
+
         Introduce makeAtomString()
         https://bugs.webkit.org/show_bug.cgi?id=239464
 

Modified: trunk/Source/WTF/wtf/text/WTFString.h (293055 => 293056)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-04-20 02:32:43 UTC (rev 293056)
@@ -193,9 +193,10 @@
 
     String& replace(UChar target, UChar replacement);
     String& replace(UChar target, StringView replacement);
+    String& replace(UChar target, ASCIILiteral);
+    String& replace(UChar target, const char*) = delete;
     String& replace(StringView target, StringView replacement);
     String& replace(unsigned start, unsigned length, StringView replacement);
-    template<unsigned characterCount> String& replaceWithLiteral(UChar target, const char (&replacement)[characterCount]);
 
     WTF_EXPORT_PRIVATE void remove(unsigned position, unsigned length = 1);
 
@@ -490,10 +491,10 @@
     return *this;
 }
 
-template<unsigned characterCount> ALWAYS_INLINE String& String::replaceWithLiteral(UChar target, const char (&characters)[characterCount])
+ALWAYS_INLINE String& String::replace(UChar target, ASCIILiteral literal)
 {
     if (m_impl)
-        m_impl = m_impl->replace(target, characters, characterCount - 1);
+        m_impl = m_impl->replace(target, literal.characters(), literal.length());
     return *this;
 }
 

Modified: trunk/Source/WebCore/ChangeLog (293055 => 293056)


--- trunk/Source/WebCore/ChangeLog	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/ChangeLog	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1,3 +1,39 @@
+2022-04-19  Chris Dumez  <cdu...@apple.com>
+
+        Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral
+        https://bugs.webkit.org/show_bug.cgi?id=239500
+
+        Reviewed by Darin Adler.
+
+        * Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:
+        (WebCore::IDBServer::SQLiteIDBBackingStore::encodeDatabaseName):
+        * display/css/DisplayTextBox.cpp:
+        (WebCore::Display::TextBox::debugDescription const):
+        * dom/Node.cpp:
+        (WebCore::Node::showNode const):
+        * dom/Text.cpp:
+        (WebCore::appendTextRepresentation):
+        * editing/EditingStyle.cpp:
+        (WebCore::StyleChange::extractTextStyles):
+        * editing/Editor.cpp:
+        (WebCore::Editor::selectedText const):
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::appendQuotedURLAttributeValue):
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::takeResults):
+        * html/URLDecomposition.cpp:
+        (WebCore::URLDecomposition::setSearch):
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::outputLayoutBox):
+        * loader/FormSubmission.cpp:
+        (WebCore::appendMailtoPostFormDataToURL):
+        * rendering/LegacyInlineTextBox.cpp:
+        (WebCore::LegacyInlineTextBox::outputLineBox const):
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::outputRenderObject const):
+        * xml/XSLTProcessor.cpp:
+        (WebCore::transformTextStringToXHTMLDocumentString):
+
 2022-04-19  Simon Fraser  <simon.fra...@apple.com>
 
         EventHandler should use a WeakPtr for m_resizeLayer

Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp (293055 => 293056)


--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -917,7 +917,7 @@
         return "%00"_s;
 
     String filename = FileSystem::encodeForFileName(databaseName);
-    filename.replaceWithLiteral('.', "%2E");
+    filename.replace('.', "%2E"_s);
 
     return filename;
 }

Modified: trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp (293055 => 293056)


--- trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/contentextensions/ContentExtensionParser.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -81,19 +81,19 @@
             domain = domain.substring(1);
         }
 
-        std::array<std::pair<UChar, const char*>, 9> escapeTable { {
-            { '\\', "\\\\" },
-            { '{', "\\{" },
-            { '}', "\\}" },
-            { '[', "\\[" },
-            { '[', "\\[" },
-            { '.', "\\." },
-            { '?', "\\?" },
-            { '*', "\\*" },
-            { '$', "\\$" }
+        std::array<std::pair<UChar, ASCIILiteral>, 9> escapeTable { {
+            { '\\', "\\\\"_s },
+            { '{', "\\{"_s },
+            { '}', "\\}"_s },
+            { '[', "\\["_s },
+            { '[', "\\["_s },
+            { '.', "\\."_s },
+            { '?', "\\?"_s },
+            { '*', "\\*"_s },
+            { '$', "\\$"_s }
         } };
         for (auto& pair : escapeTable)
-            domain = domain.replace(pair.first, StringView { pair.second });
+            domain = domain.replace(pair.first, pair.second);
 
         const char* protocolRegex = "[a-z][a-z+.-]*:\\/\\/";
         const char* allowSubdomainsRegex = "(.*\\.)*";

Modified: trunk/Source/WebCore/display/css/DisplayTextBox.cpp (293055 => 293056)


--- trunk/Source/WebCore/display/css/DisplayTextBox.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/display/css/DisplayTextBox.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -54,8 +54,8 @@
 
     stream << boxName() << " " << absoluteBoxRect() << " (" << this << ")";
     auto textContent = text().originalContent().substring(text().start(), text().length()).toString();
-    textContent.replaceWithLiteral('\\', "\\\\");
-    textContent.replaceWithLiteral('\n', "\\n");
+    textContent.replace('\\', "\\\\"_s);
+    textContent.replace('\n', "\\n"_s);
     const size_t maxPrintedLength = 80;
     if (textContent.length() > maxPrintedLength) {
         auto substring = StringView(textContent).left(maxPrintedLength);

Modified: trunk/Source/WebCore/dom/Node.cpp (293055 => 293056)


--- trunk/Source/WebCore/dom/Node.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/dom/Node.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1799,8 +1799,8 @@
         prefix = "";
     if (isTextNode()) {
         String value = nodeValue();
-        value.replaceWithLiteral('\\', "\\\\");
-        value.replaceWithLiteral('\n', "\\n");
+        value.replace('\\', "\\\\"_s);
+        value.replace('\n', "\\n"_s);
         fprintf(stderr, "%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), this, value.utf8().data());
     } else {
         StringBuilder attrs;

Modified: trunk/Source/WebCore/dom/Text.cpp (293055 => 293056)


--- trunk/Source/WebCore/dom/Text.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/dom/Text.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -228,8 +228,8 @@
     String value = text.data();
     builder.append(" length="_s, value.length());
 
-    value.replaceWithLiteral('\\', "\\\\");
-    value.replaceWithLiteral('\n', "\\n");
+    value.replace('\\', "\\\\"_s);
+    value.replace('\n', "\\n"_s);
     
     constexpr size_t maxDumpLength = 30;
     if (value.length() > maxDumpLength)

Modified: trunk/Source/WebCore/editing/EditingStyle.cpp (293055 => 293056)


--- trunk/Source/WebCore/editing/EditingStyle.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/editing/EditingStyle.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1853,7 +1853,7 @@
 
     m_applyFontFace = style.getPropertyValue(CSSPropertyFontFamily);
     // Remove quotes for Outlook 2007 compatibility. See https://bugs.webkit.org/show_bug.cgi?id=79448
-    m_applyFontFace.replaceWithLiteral('\"', "");
+    m_applyFontFace.replace('\"', ""_s);
     style.removeProperty(CSSPropertyFontFamily);
 
     if (RefPtr<CSSValue> fontSize = style.getPropertyCSSValue(CSSPropertyFontSize)) {

Modified: trunk/Source/WebCore/editing/Editor.cpp (293055 => 293056)


--- trunk/Source/WebCore/editing/Editor.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/editing/Editor.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -3334,7 +3334,7 @@
 {
     // We remove '\0' characters because they are not visibly rendered to the user.
     auto range = m_document.selection().selection().firstRange();
-    return range ? plainText(*range, behaviors).replaceWithLiteral('\0', "") : emptyString();
+    return range ? plainText(*range, behaviors).replace('\0', ""_s) : emptyString();
 }
 
 RefPtr<TextPlaceholderElement> Editor::insertTextPlaceholder(const IntSize& size)

Modified: trunk/Source/WebCore/editing/MarkupAccumulator.cpp (293055 => 293056)


--- trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/editing/MarkupAccumulator.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -289,7 +289,7 @@
         // minimal escaping for _javascript_ urls
         if (resolvedURLString.contains('"')) {
             if (resolvedURLString.contains('\''))
-                resolvedURLString.replaceWithLiteral('"', "&quot;");
+                resolvedURLString.replace('"', "&quot;"_s);
             else
                 quoteChar = '\'';
         }

Modified: trunk/Source/WebCore/editing/markup.cpp (293055 => 293056)


--- trunk/Source/WebCore/editing/markup.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/editing/markup.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -421,7 +421,7 @@
         result.append(string);
     result.append(takeMarkup());
     // Remove '\0' characters because they are not visibly rendered to the user.
-    return result.toString().replaceWithLiteral('\0', "");
+    return result.toString().replace('\0', ""_s);
 }
 
 void StyledMarkupAccumulator::appendText(StringBuilder& out, const Text& text)

Modified: trunk/Source/WebCore/html/URLDecomposition.cpp (293055 => 293056)


--- trunk/Source/WebCore/html/URLDecomposition.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/html/URLDecomposition.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -235,7 +235,7 @@
     } else {
         String newSearch = value;
         // Make sure that '#' in the query does not leak to the hash.
-        fullURL.setQuery(newSearch.replaceWithLiteral('#', "%23"));
+        fullURL.setQuery(newSearch.replace('#', "%23"_s));
     }
     setFullURL(fullURL);
 }

Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (293055 => 293056)


--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -498,8 +498,8 @@
         auto textContent = downcast<InlineTextBox>(layoutBox).content();
         stream << " length->(" << textContent.length() << ")";
 
-        textContent.replaceWithLiteral('\\', "\\\\");
-        textContent.replaceWithLiteral('\n', "\\n");
+        textContent.replace('\\', "\\\\"_s);
+        textContent.replace('\n', "\\n"_s);
 
         const size_t maxPrintedLength = 80;
         if (textContent.length() > maxPrintedLength) {

Modified: trunk/Source/WebCore/loader/FormSubmission.cpp (293055 => 293056)


--- trunk/Source/WebCore/loader/FormSubmission.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/loader/FormSubmission.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -70,13 +70,13 @@
 
     if (equalLettersIgnoringASCIICase(encodingType, "text/plain")) {
         // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are encoded as %20.
-        body = PAL::decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' '));
+        body = PAL::decodeURLEscapeSequences(body.replace('&', "\r\n"_s).replace('+', ' '));
     }
 
     Vector<char> bodyData;
     bodyData.append("body=", 5);
     FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8());
-    body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20");
+    body = String(bodyData.data(), bodyData.size()).replace('+', "%20"_s);
 
     auto query = url.query();
     if (query.isEmpty())

Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp (293055 => 293056)


--- trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -309,7 +309,7 @@
 
     ResourceResponse response { { { }, "http://example.com/"_s }, { }, -1, { } };
     response.setHTTPStatusCode(200);
-    String escapedSuggestedFilename = String(suggestedFilename).replace('\\', "\\\\").replace('"', "\\\"");
+    String escapedSuggestedFilename = String(suggestedFilename).replace('\\', "\\\\"_s).replace('"', "\\\""_s);
     response.setHTTPHeaderField(HTTPHeaderName::ContentDisposition, makeString("attachment; filename=\"", escapedSuggestedFilename, '"'));
     return response.suggestedFilename();
 }

Modified: trunk/Source/WebCore/platform/text/DateTimeFormat.cpp (293055 => 293056)


--- trunk/Source/WebCore/platform/text/DateTimeFormat.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/platform/text/DateTimeFormat.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -265,7 +265,7 @@
         if (literal[i] == '\'')
             buffer.append("''");
         else {
-            buffer.append('\'', String { literal.substring(i) }.replace('\'', "''"), '\'');
+            buffer.append('\'', String { literal.substring(i) }.replace('\'', "''"_s), '\'');
             return;
         }
     }

Modified: trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp (293055 => 293056)


--- trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/rendering/LegacyInlineTextBox.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -528,8 +528,8 @@
 
     String value = renderer().text();
     value = value.substring(start(), len());
-    value.replaceWithLiteral('\\', "\\\\");
-    value.replaceWithLiteral('\n', "\\n");
+    value.replace('\\', "\\\\"_s);
+    value.replace('\n', "\\n"_s);
     stream << boxName() << " " << FloatRect(x(), y(), width(), height()) << " (" << this << ") renderer->(" << &renderer() << ") run(" << start() << ", " << start() + len() << ") \"" << value.utf8().data() << "\"";
     stream.nextLine();
 }

Modified: trunk/Source/WebCore/rendering/RenderObject.cpp (293055 => 293056)


--- trunk/Source/WebCore/rendering/RenderObject.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/rendering/RenderObject.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1265,8 +1265,8 @@
             String value = node()->nodeValue();
             stream << " length->(" << value.length() << ")";
 
-            value.replaceWithLiteral('\\', "\\\\");
-            value.replaceWithLiteral('\n', "\\n");
+            value.replace('\\', "\\\\"_s);
+            value.replace('\n', "\\n"_s);
             
             const int maxPrintedLength = 80;
             if (value.length() > maxPrintedLength) {

Modified: trunk/Source/WebCore/xml/XSLTProcessor.cpp (293055 => 293056)


--- trunk/Source/WebCore/xml/XSLTProcessor.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebCore/xml/XSLTProcessor.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -45,8 +45,8 @@
 static inline void transformTextStringToXHTMLDocumentString(String& text)
 {
     // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
-    text.replaceWithLiteral('&', "&amp;");
-    text.replaceWithLiteral('<', "&lt;");
+    text.replace('&', "&amp;"_s);
+    text.replace('<', "&lt;"_s);
     text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
         "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
         "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"

Modified: trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp (293055 => 293056)


--- trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1592,7 +1592,7 @@
 
 static String escapeForJSON(String s)
 {
-    return s.replace('\\', "\\\\").replace('"', "\\\"");
+    return s.replace('\\', "\\\\"_s).replace('"', "\\\""_s);
 }
 
 template<typename IdentifierType>

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp (293055 => 293056)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebResourceLoadObserver.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -384,7 +384,7 @@
         RELEASE_LOG(ResourceLoadStatistics, "ResourceLoadObserver::logUserInteraction: counter=%" PRIu64 ": " str, counter, ##__VA_ARGS__)
 
         auto escapeForJSON = [](String s) {
-            s.replace('\\', "\\\\").replace('"', "\\\"");
+            s.replace('\\', "\\\\"_s).replace('"', "\\\""_s);
             return s;
         };
         auto escapedURL = escapeForJSON(url.string());

Modified: trunk/Tools/ChangeLog (293055 => 293056)


--- trunk/Tools/ChangeLog	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Tools/ChangeLog	2022-04-20 02:32:43 UTC (rev 293056)
@@ -1,3 +1,13 @@
+2022-04-19  Chris Dumez  <cdu...@apple.com>
+
+        Replace String::replaceWithLiteral() with a String::replace() overload that takes in an ASCIILiteral
+        https://bugs.webkit.org/show_bug.cgi?id=239500
+
+        Reviewed by Darin Adler.
+
+        * TestWebKitAPI/Tests/WTF/WTFString.cpp:
+        (TestWebKitAPI::TEST):
+
 2022-04-19  Wenson Hsieh  <wenson_hs...@apple.com>
 
         [iOS] Dictation text that contains emojis is inserted twice upon finalization

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp (293055 => 293056)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -239,38 +239,38 @@
     // Cases for 8Bit source.
     String testString = "1224"_s;
     EXPECT_TRUE(testString.is8Bit());
-    testString.replaceWithLiteral('2', "");
+    testString.replace('2', ""_s);
     EXPECT_STREQ("14", testString.utf8().data());
 
     testString = "1224"_s;
     EXPECT_TRUE(testString.is8Bit());
-    testString.replaceWithLiteral('2', "3");
+    testString.replace('2', "3"_s);
     EXPECT_STREQ("1334", testString.utf8().data());
 
     testString = "1224"_s;
     EXPECT_TRUE(testString.is8Bit());
-    testString.replaceWithLiteral('2', "555");
+    testString.replace('2', "555"_s);
     EXPECT_STREQ("15555554", testString.utf8().data());
 
     testString = "1224"_s;
     EXPECT_TRUE(testString.is8Bit());
-    testString.replaceWithLiteral('3', "NotFound");
+    testString.replace('3', "NotFound"_s);
     EXPECT_STREQ("1224", testString.utf8().data());
 
     // Cases for 16Bit source.
     testString = String::fromUTF8("résumé");
     EXPECT_FALSE(testString.is8Bit());
-    testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), "e");
+    testString.replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "e"_s);
     EXPECT_STREQ("resume", testString.utf8().data());
 
     testString = String::fromUTF8("résumé");
     EXPECT_FALSE(testString.is8Bit());
-    testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), "");
+    testString.replace(UChar(0x00E9 /*U+00E9 is 'é'*/), ""_s);
     EXPECT_STREQ("rsum", testString.utf8().data());
 
     testString = String::fromUTF8("résumé");
     EXPECT_FALSE(testString.is8Bit());
-    testString.replaceWithLiteral('3', "NotFound");
+    testString.replace('3', "NotFound"_s);
     EXPECT_STREQ("résumé", testString.utf8().data());
 }
 

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp (293055 => 293056)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp	2022-04-20 02:24:24 UTC (rev 293055)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/atspi/AccessibilityUIElementAtspi.cpp	2022-04-20 02:32:43 UTC (rev 293056)
@@ -889,7 +889,7 @@
     if (!m_element->interfaces().contains(WebCore::AccessibilityObjectAtspi::Interface::Text))
         return JSStringCreateWithCharacters(nullptr, 0);
 
-    auto value = makeString("AXValue: ", m_element->text().replace("\n", "<\\n>").replace(objectReplacementCharacter, "<obj>"));
+    auto value = makeString("AXValue: ", m_element->text().replace('\n', "<\\n>"_s).replace(objectReplacementCharacter, "<obj>"_s));
     return OpaqueJSString::tryCreate(value).leakRef();
 }
 
@@ -1197,7 +1197,7 @@
         auto attributes = m_element->textAttributes(i);
         auto rangeStart = std::max<int>(location, attributes.startOffset);
         auto rangeEnd = std::min<int>(limit, attributes.endOffset);
-        builder.append("\n\tRange attributes for '", text.substring(rangeStart, rangeEnd - rangeStart).replace("\n", "<\\n>").replace(objectReplacementCharacter, "<obj>"), "':");
+        builder.append("\n\tRange attributes for '", text.substring(rangeStart, rangeEnd - rangeStart).replace('\n', "<\\n>"_s).replace(objectReplacementCharacter, "<obj>"_s), "':");
         buildAttributes(attributes);
         endOffset = attributes.endOffset;
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to