Title: [293760] trunk/Source
Revision
293760
Author
cdu...@apple.com
Date
2022-05-03 23:18:46 -0700 (Tue, 03 May 2022)

Log Message

Replace String::remove() by a makeStringByRemoving() free function
https://bugs.webkit.org/show_bug.cgi?id=239995

Reviewed by Yusuke Suzuki.

Replace String::remove() by a makeStringByRemoving() free function. This is a
step towards making String immutable.

* Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:
(WebKit::lastCNAMEDomain):
* Source/WebKit/UIProcess/Inspector/win/InspectorResourceURLSchemeHandler.cpp:
(WebKit::InspectorResourceURLSchemeHandler::platformStartTask):
* Source/WTF/wtf/URL.cpp:
(WTF::URL::remove):
* Source/WTF/wtf/text/WTFString.cpp:
(WTF::makeStringByRemoving):
(WTF::String::removeInternal): Deleted.
(WTF::String::remove): Deleted.
* Source/WTF/wtf/text/WTFString.h:
* Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp:
(WebCore::RTCDTMFSender::playNextTone):
* Source/WebCore/dom/CharacterData.cpp:
(WebCore::CharacterData::deleteData):
* Source/WebCore/dom/FragmentDirectiveParser.cpp:
(WebCore::FragmentDirectiveParser::parseFragmentDirective):
* Source/WebCore/dom/Range.cpp:
(WebCore::processContentsBetweenOffsets):
* Source/WebCore/editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::deleteInsignificantText):
* Source/WebCore/inspector/InspectorOverlayLabel.cpp:
(WebCore::InspectorOverlayLabel::draw):
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
(WebCore::InspectorStyleSheet::deleteRule):
* Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp:
(WebCore::GStreamerMediaDescription::extractCodecName):
* Source/WebCore/platform/network/curl/CookieJarDB.cpp:
(WebCore::CookieJarDB::deleteCookie):
* Source/WebCore/platform/text/win/LocaleWin.cpp:
(WebCore::LocaleWin::shortTimeFormat):

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

Modified Paths

Diff

Modified: trunk/Source/WTF/wtf/URL.cpp (293759 => 293760)


--- trunk/Source/WTF/wtf/URL.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WTF/wtf/URL.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -569,8 +569,7 @@
     ASSERT(start < m_string.length());
     ASSERT(length <= m_string.length() - start);
 
-    auto stringAfterRemoval = std::exchange(m_string, { });
-    stringAfterRemoval.remove(start, length);
+    auto stringAfterRemoval = makeStringByRemoving(std::exchange(m_string, { }), start, length);
     parse(WTFMove(stringAfterRemoval));
 }
 

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (293759 => 293760)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -78,27 +78,16 @@
     return m_impl->characterStartingAt(i);
 }
 
-template<typename CharacterType> inline void String::removeInternal(const CharacterType* characters, unsigned position, unsigned lengthToRemove)
+String makeStringByRemoving(const String& string, unsigned position, unsigned lengthToRemove)
 {
-    CharacterType* data;
-    auto newImpl = StringImpl::createUninitialized(length() - lengthToRemove, data);
-    StringImpl::copyCharacters(data, characters, position);
-    StringImpl::copyCharacters(data + position, characters + position + lengthToRemove, length() - lengthToRemove - position);
-    m_impl = WTFMove(newImpl);
-}
-
-void String::remove(unsigned position, unsigned lengthToRemove)
-{
     if (!lengthToRemove)
-        return;
-    auto length = this->length();
+        return string;
+    auto length = string.length();
     if (position >= length)
-        return;
+        return string;
     lengthToRemove = std::min(lengthToRemove, length - position);
-    if (is8Bit())
-        removeInternal(characters8(), position, lengthToRemove);
-    else
-        removeInternal(characters16(), position, lengthToRemove);
+    StringView view { string };
+    return makeString(view.left(position), view.substring(position + lengthToRemove));
 }
 
 String String::substring(unsigned position, unsigned length) const

Modified: trunk/Source/WTF/wtf/text/WTFString.h (293759 => 293760)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-05-04 06:18:46 UTC (rev 293760)
@@ -192,8 +192,6 @@
     bool endsWith(char character) const { return endsWith(static_cast<UChar>(character)); }
     bool hasInfixEndingAt(StringView suffix, unsigned end) const;
 
-    WTF_EXPORT_PRIVATE void remove(unsigned position, unsigned length = 1);
-
     WTF_EXPORT_PRIVATE String substring(unsigned position, unsigned length = MaxLength) const;
     WTF_EXPORT_PRIVATE String substringSharingImpl(unsigned position, unsigned length = MaxLength) const;
     String left(unsigned length) const { return substring(0, length); }
@@ -323,8 +321,6 @@
     static constexpr unsigned MaxLength = StringImpl::MaxLength;
 
 private:
-    template<typename CharacterType> void removeInternal(const CharacterType*, unsigned, unsigned);
-
     template<bool allowEmptyEntries> void splitInternal(UChar separator, const SplitFunctor&) const;
     template<bool allowEmptyEntries> Vector<String> splitInternal(UChar separator) const;
     template<bool allowEmptyEntries> Vector<String> splitInternal(StringView separator) const;
@@ -492,6 +488,8 @@
 
 String makeStringByReplacingAll(const String&, UChar target, const char*) = delete;
 
+WTF_EXPORT_PRIVATE String WARN_UNUSED_RETURN makeStringByRemoving(const String&, unsigned position, unsigned lengthToRemove);
+
 template<size_t inlineCapacity> inline String String::make8BitFrom16BitSource(const Vector<UChar, inlineCapacity>& buffer)
 {
     return make8BitFrom16BitSource(buffer.data(), buffer.size());
@@ -627,6 +625,7 @@
 using WTF::charactersToDouble;
 using WTF::charactersToFloat;
 using WTF::emptyString;
+using WTF::makeStringByRemoving;
 using WTF::makeStringByReplacingAll;
 using WTF::nullString;
 using WTF::equal;

Modified: trunk/Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp (293759 => 293760)


--- trunk/Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/Modules/mediastream/RTCDTMFSender.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -127,7 +127,7 @@
     }
 
     auto currentTone = m_tones.left(1);
-    m_tones.remove(0);
+    m_tones = m_tones.substring(1);
 
     m_backend->playTone(currentTone, m_duration, m_interToneGap);
     dispatchEvent(RTCDTMFToneChangeEvent::create(currentTone));

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (293759 => 293760)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -150,8 +150,7 @@
 
     count = std::min(count, length() - offset);
 
-    String newData = m_data;
-    newData.remove(offset, count);
+    auto newData = makeStringByRemoving(m_data, offset, count);
     setDataAndUpdate(WTFMove(newData), offset, count, 0);
 
     return { };

Modified: trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp (293759 => 293760)


--- trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -108,7 +108,7 @@
         }
         
         if (tokens.last().startsWith('-') && tokens.last().length() > 1) {
-            tokens.last().remove(0);
+            tokens.last() = tokens.last().substring(1);
             
             if (auto suffix = WTF::URLParser::formURLDecode(tokens.takeLast()))
                 parsedTextDirective.suffix = WTFMove(*suffix);

Modified: trunk/Source/WebCore/dom/Range.cpp (293759 => 293760)


--- trunk/Source/WebCore/dom/Range.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/dom/Range.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -473,9 +473,8 @@
                 result = WTFMove(processingInstruction);
         }
         if (action == Range::Extract || action == Range::Delete) {
-            String data { instruction.data() };
-            data.remove(startOffset, endOffset - startOffset);
-            instruction.setData(data);
+            auto data = "" startOffset, endOffset - startOffset);
+            instruction.setData(WTFMove(data));
         }
         break;
     }

Modified: trunk/Source/WebCore/editing/CompositeEditCommand.cpp (293759 => 293760)


--- trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/editing/CompositeEditCommand.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -1008,7 +1008,7 @@
     document().updateLayout();
 
     bool wholeTextNodeIsEmpty = false;
-    String str;
+    String string;
     auto determineRemovalMode = [&] {
         ScriptDisallowedScope::InMainThread scriptDisallowedScope;
         RenderText* textRenderer = textNode.renderer();
@@ -1037,15 +1037,15 @@
 
             unsigned gapEnd = run ? run->start() : length;
             bool indicesIntersect = start <= gapEnd && end >= gapStart;
-            int gapLen = gapEnd - gapStart;
-            if (indicesIntersect && gapLen > 0) {
+            int gapLength = gapEnd - gapStart;
+            if (indicesIntersect && gapLength > 0) {
                 gapStart = std::max(gapStart, start);
                 gapEnd = std::min(gapEnd, end);
-                if (str.isNull())
-                    str = textNode.data().substring(start, end - start);
-                // remove text in the gap
-                str.remove(gapStart - start - removed, gapLen);
-                removed += gapLen;
+                if (string.isNull())
+                    string = textNode.data().substring(start, end - start);
+                // Remove text in the gap.
+                string = makeStringByRemoving(string, gapStart - start - removed, gapLength);
+                removed += gapLength;
             }
 
             previousRun = run;
@@ -1060,10 +1060,10 @@
         return;
     }
 
-    if (!str.isNull()) {
+    if (!string.isNull()) {
         // Replace the text between start and end with our pruned version.
-        if (!str.isEmpty())
-            replaceTextInNode(textNode, start, end - start, str);
+        if (!string.isEmpty())
+            replaceTextInNode(textNode, start, end - start, string);
         else {
             // Assert that we are not going to delete all of the text in the node.
             // If we were, that should have been done above with the call to 

Modified: trunk/Source/WebCore/inspector/InspectorOverlayLabel.cpp (293759 => 293760)


--- trunk/Source/WebCore/inspector/InspectorOverlayLabel.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/inspector/InspectorOverlayLabel.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -239,7 +239,7 @@
                 text = makeString(text, ellipsis);
                 while (currentLineWidth + textWidth + (labelPadding * 2) > maximumLineWidth && text.length() > 1) {
                     // Remove the second from last character (the character before the ellipsis) and remeasure.
-                    text.remove(text.length() - 2);
+                    text = makeStringByRemoving(text, text.length() - 2, 1);
                     textRun = TextRun(text);
                     textWidth = font.width(textRun);
                 }

Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (293759 => 293760)


--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -1062,8 +1062,7 @@
 
     // |rule| MAY NOT be addressed after this!
 
-    String sheetText = m_parsedStyleSheet->text();
-    sheetText.remove(sourceData->ruleHeaderRange.start, sourceData->ruleBodyRange.end - sourceData->ruleHeaderRange.start + 1);
+    auto sheetText = makeStringByRemoving(m_parsedStyleSheet->text(), sourceData->ruleHeaderRange.start, sourceData->ruleBodyRange.end - sourceData->ruleHeaderRange.start + 1);
     setText(sheetText);
     fireStyleSheetChanged();
     return { };

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp (293759 => 293760)


--- trunk/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/mse/GStreamerMediaDescription.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -82,7 +82,7 @@
         size_t braceStart = codecName.find(" (");
         size_t braceEnd = codecName.find(")");
         if (braceStart != notFound && braceEnd != notFound)
-            codecName.remove(braceStart, braceEnd - braceStart);
+            codecName = makeStringByRemoving(codecName, braceStart, braceEnd - braceStart);
     }
 
     return codecName;

Modified: trunk/Source/WebCore/platform/network/curl/CookieJarDB.cpp (293759 => 293760)


--- trunk/Source/WebCore/platform/network/curl/CookieJarDB.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/platform/network/curl/CookieJarDB.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -596,7 +596,7 @@
 
     String urlCopied = String(url);
     if (urlCopied.startsWith('.'))
-        urlCopied.remove(0, 1);
+        urlCopied = urlCopied.substring(1);
 
     URL urlObj({ }, urlCopied);
     if (urlObj.isValid()) {

Modified: trunk/Source/WebCore/platform/text/win/LocaleWin.cpp (293759 => 293760)


--- trunk/Source/WebCore/platform/text/win/LocaleWin.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebCore/platform/text/win/LocaleWin.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -326,7 +326,7 @@
         builder.append("ss");
         size_t pos = format.reverseFind(builder.toString());
         if (pos != notFound)
-            format.remove(pos, builder.length());
+            format = makeStringByRemoving(format, pos, builder.length());
     }
     m_timeFormatWithoutSeconds = convertWindowsDateTimeFormat(format);
     return m_timeFormatWithoutSeconds;

Modified: trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm (293759 => 293760)


--- trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm	2022-05-04 06:18:46 UTC (rev 293760)
@@ -151,7 +151,7 @@
     if (auto* lastResolvedCNAMEInChain = [cnames lastObject]) {
         auto cname = String(lastResolvedCNAMEInChain);
         if (cname.endsWith('.'))
-            cname.remove(cname.length() - 1);
+            cname = cname.left(cname.length() - 1);
         return WebCore::RegistrableDomain::uncheckedCreateFromHost(cname);
     }
 

Modified: trunk/Source/WebKit/UIProcess/Inspector/win/InspectorResourceURLSchemeHandler.cpp (293759 => 293760)


--- trunk/Source/WebKit/UIProcess/Inspector/win/InspectorResourceURLSchemeHandler.cpp	2022-05-04 06:14:20 UTC (rev 293759)
+++ trunk/Source/WebKit/UIProcess/Inspector/win/InspectorResourceURLSchemeHandler.cpp	2022-05-04 06:18:46 UTC (rev 293760)
@@ -45,7 +45,7 @@
     auto requestURL = task.request().url();
     auto requestPath = requestURL.fileSystemPath();
     if (requestPath.startsWith("\\"))
-        requestPath.remove(0);
+        requestPath = requestPath.substring(1);
     auto path = URL(adoptCF(CFBundleCopyBundleURL(WebCore::webKitBundle())).get()).fileSystemPath();
     path = FileSystem::pathByAppendingComponent(path, "WebInspectorUI"_s);
     path = FileSystem::pathByAppendingComponent(path, requestPath);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to