Title: [292942] trunk/Source
Revision
292942
Author
cdu...@apple.com
Date
2022-04-16 13:31:36 -0700 (Sat, 16 Apr 2022)

Log Message

Replace complex String::insert() with a simplified makeStringByInserting() free function
https://bugs.webkit.org/show_bug.cgi?id=239370

Reviewed by Darin Adler.

Source/WebCore:

* Modules/mediasource/MediaSource.cpp:
(WebCore::addVP9FullRangeVideoFlagToContentType):
* dom/CharacterData.cpp:
(WebCore::CharacterData::insertData):
(WebCore::CharacterData::replaceData):
* html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::setRangeText):
* platform/network/DataURLDecoder.cpp:
(WebCore::DataURLDecoder::DecodeTask::process):
* platform/win/PasteboardWin.cpp:
(WebCore::createGlobalImageFileDescriptor):

Source/WTF:

* wtf/text/WTFString.cpp:
(WTF::makeStringByInserting):
(WTF::String::insert): Deleted.
(WTF::String::append): Deleted.
* wtf/text/WTFString.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (292941 => 292942)


--- trunk/Source/WTF/ChangeLog	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WTF/ChangeLog	2022-04-16 20:31:36 UTC (rev 292942)
@@ -1,3 +1,16 @@
+2022-04-16  Chris Dumez  <cdu...@apple.com>
+
+        Replace complex String::insert() with a simplified makeStringByInserting() free function
+        https://bugs.webkit.org/show_bug.cgi?id=239370
+
+        Reviewed by Darin Adler.
+
+        * wtf/text/WTFString.cpp:
+        (WTF::makeStringByInserting):
+        (WTF::String::insert): Deleted.
+        (WTF::String::append): Deleted.
+        * wtf/text/WTFString.h:
+
 2022-04-15  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         [WebGPU] Implement hardware limits

Modified: trunk/Source/WTF/wtf/text/StringConcatenate.h (292941 => 292942)


--- trunk/Source/WTF/wtf/text/StringConcatenate.h	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WTF/wtf/text/StringConcatenate.h	2022-04-16 20:31:36 UTC (rev 292942)
@@ -478,11 +478,17 @@
     return result;
 }
 
+inline String makeStringByInserting(StringView originalString, StringView stringToInsert, unsigned position)
+{
+    return makeString(originalString.left(position), stringToInsert, originalString.substring(position));
+}
+
 } // namespace WTF
 
 using WTF::Indentation;
 using WTF::IndentationScope;
 using WTF::makeString;
+using WTF::makeStringByInserting;
 using WTF::pad;
 using WTF::lowercase;
 using WTF::tryMakeString;

Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (292941 => 292942)


--- trunk/Source/WTF/wtf/text/WTFString.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -78,116 +78,6 @@
     return codePointCompare(a.impl(), b.impl());
 }
 
-void String::insert(const String& string, unsigned position)
-{
-    // FIXME: This is extremely inefficient. So much so that we might want to take this out of String's API.
-
-    unsigned lengthToInsert = string.length();
-
-    if (!lengthToInsert) {
-        if (string.isNull())
-            return;
-        if (isNull())
-            m_impl = string.impl();
-        return;
-    }
-
-    if (position >= length()) {
-        if (string.is8Bit())
-            append(string.characters8(), string.length());
-        else
-            append(string.characters16(), string.length());
-        return;
-    }
-
-    if (lengthToInsert > MaxLength - length())
-        CRASH();
-
-    if (is8Bit() && string.is8Bit()) {
-        LChar* data;
-        auto newString = StringImpl::createUninitialized(length() + lengthToInsert, data);
-        StringView(*m_impl).left(position).getCharactersWithUpconvert(data);
-        StringView(string).getCharactersWithUpconvert(data + position);
-        StringView(*m_impl).substring(position).getCharactersWithUpconvert(data + position + lengthToInsert);
-        m_impl = WTFMove(newString);
-    } else {
-        UChar* data;
-        auto newString = StringImpl::createUninitialized(length() + lengthToInsert, data);
-        StringView(*m_impl).left(position).getCharactersWithUpconvert(data);
-        StringView(string).getCharactersWithUpconvert(data + position);
-        StringView(*m_impl).substring(position).getCharactersWithUpconvert(data + position + lengthToInsert);
-        m_impl = WTFMove(newString);
-    }
-}
-
-void String::append(const LChar* charactersToAppend, unsigned lengthToAppend)
-{
-    // FIXME: This is extremely inefficient. So much so that we might want to take this out of String's API.
-
-    if (!m_impl) {
-        if (!charactersToAppend)
-            return;
-        m_impl = StringImpl::create(charactersToAppend, lengthToAppend);
-        return;
-    }
-
-    if (!lengthToAppend)
-        return;
-
-    ASSERT(charactersToAppend);
-
-    unsigned strLength = m_impl->length();
-
-    if (m_impl->is8Bit()) {
-        if (lengthToAppend > MaxLength - strLength)
-            CRASH();
-        LChar* data;
-        auto newImpl = StringImpl::createUninitialized(strLength + lengthToAppend, data);
-        StringImpl::copyCharacters(data, m_impl->characters8(), strLength);
-        StringImpl::copyCharacters(data + strLength, charactersToAppend, lengthToAppend);
-        m_impl = WTFMove(newImpl);
-        return;
-    }
-
-    if (lengthToAppend > MaxLength - strLength)
-        CRASH();
-    UChar* data;
-    auto newImpl = StringImpl::createUninitialized(length() + lengthToAppend, data);
-    StringImpl::copyCharacters(data, m_impl->characters16(), strLength);
-    StringImpl::copyCharacters(data + strLength, charactersToAppend, lengthToAppend);
-    m_impl = WTFMove(newImpl);
-}
-
-void String::append(const UChar* charactersToAppend, unsigned lengthToAppend)
-{
-    // FIXME: This is extremely inefficient. So much so that we might want to take this out of String's API.
-
-    if (!m_impl) {
-        if (!charactersToAppend)
-            return;
-        m_impl = StringImpl::create(charactersToAppend, lengthToAppend);
-        return;
-    }
-
-    if (!lengthToAppend)
-        return;
-
-    unsigned strLength = m_impl->length();
-
-    ASSERT(charactersToAppend);
-    if (lengthToAppend > MaxLength - strLength)
-        CRASH();
-    UChar* data;
-    auto newImpl = StringImpl::createUninitialized(strLength + lengthToAppend, data);
-    if (m_impl->is8Bit())
-        StringImpl::copyCharacters(data, characters8(), strLength);
-    else
-        StringImpl::copyCharacters(data, characters16(), strLength);
-    StringImpl::copyCharacters(data + strLength, charactersToAppend, lengthToAppend);
-    m_impl = WTFMove(newImpl);
-}
-
-
 UChar32 String::characterStartingAt(unsigned i) const
 {
     if (!m_impl || i >= m_impl->length())

Modified: trunk/Source/WTF/wtf/text/WTFString.h (292941 => 292942)


--- trunk/Source/WTF/wtf/text/WTFString.h	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2022-04-16 20:31:36 UTC (rev 292942)
@@ -190,8 +190,6 @@
     bool endsWith(char character) const { return endsWith(static_cast<UChar>(character)); }
     bool hasInfixEndingAt(StringView suffix, unsigned end) const;
 
-    WTF_EXPORT_PRIVATE void insert(const String&, unsigned position);
-
     String& replace(UChar target, UChar replacement);
     String& replace(UChar target, StringView replacement);
     String& replace(StringView target, StringView replacement);
@@ -334,10 +332,6 @@
 private:
     template<typename CharacterType> void removeInternal(const CharacterType*, unsigned, unsigned);
 
-    // FIXME: Only used by insert(), we should consider dropping them.
-    void append(const LChar*, unsigned length);
-    void append(const UChar*, unsigned length);
-
     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;

Modified: trunk/Source/WebCore/ChangeLog (292941 => 292942)


--- trunk/Source/WebCore/ChangeLog	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/ChangeLog	2022-04-16 20:31:36 UTC (rev 292942)
@@ -1,3 +1,22 @@
+2022-04-16  Chris Dumez  <cdu...@apple.com>
+
+        Replace complex String::insert() with a simplified makeStringByInserting() free function
+        https://bugs.webkit.org/show_bug.cgi?id=239370
+
+        Reviewed by Darin Adler.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::addVP9FullRangeVideoFlagToContentType):
+        * dom/CharacterData.cpp:
+        (WebCore::CharacterData::insertData):
+        (WebCore::CharacterData::replaceData):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::setRangeText):
+        * platform/network/DataURLDecoder.cpp:
+        (WebCore::DataURLDecoder::DecodeTask::process):
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::createGlobalImageFileDescriptor):
+
 2022-04-15  Chris Dumez  <cdu...@apple.com>
 
         Leverage StringView in more places to avoid some String allocations

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (292941 => 292942)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -650,8 +650,7 @@
         if (position == notFound)
             continue;
 
-        rawType.insert(".00"_s, position + codec.length());
-        return ContentType(rawType);
+        return ContentType(makeStringByInserting(rawType, ".00"_s, position + codec.length()));
     }
     return type;
 }

Modified: trunk/Source/WebCore/dom/CharacterData.cpp (292941 => 292942)


--- trunk/Source/WebCore/dom/CharacterData.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/dom/CharacterData.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -138,9 +138,8 @@
     if (offset > length())
         return Exception { IndexSizeError };
 
-    String newData = m_data;
-    newData.insert(data, offset);
-    setDataAndUpdate(newData, offset, 0, data.length());
+    auto newData = makeStringByInserting(m_data, data, offset);
+    setDataAndUpdate(WTFMove(newData), offset, 0, data.length());
 
     return { };
 }
@@ -154,7 +153,7 @@
 
     String newData = m_data;
     newData.remove(offset, count);
-    setDataAndUpdate(newData, offset, count, 0);
+    setDataAndUpdate(WTFMove(newData), offset, count, 0);
 
     return { };
 }
@@ -166,10 +165,9 @@
 
     count = std::min(count, length() - offset);
 
-    String newData = m_data;
-    newData.remove(offset, count);
-    newData.insert(data, offset);
-    setDataAndUpdate(newData, offset, count, data.length());
+    StringView oldDataView { m_data };
+    auto newData = makeString(oldDataView.left(offset), data, oldDataView.substring(offset + count));
+    setDataAndUpdate(WTFMove(newData), offset, count, data.length());
 
     return { };
 }

Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (292941 => 292942)


--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -259,7 +259,7 @@
     if (start < end)
         text.replace(start, end - start, replacement);
     else
-        text.insert(replacement, start);
+        text = makeStringByInserting(text, replacement, start);
 
     setValue(text, TextFieldEventBehavior::DispatchNoEvent, TextControlSetValueSelection::DoNotSet);
 

Modified: trunk/Source/WebCore/platform/network/DataURLDecoder.cpp (292941 => 292942)


--- trunk/Source/WebCore/platform/network/DataURLDecoder.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/platform/network/DataURLDecoder.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -118,7 +118,7 @@
         auto mediaType = (isBase64 ? header.left(mediaTypeEnd) : header).toString();
         mediaType = stripLeadingAndTrailingHTTPSpaces(mediaType);
         if (mediaType.startsWith(';'))
-            mediaType.insert("text/plain"_s, 0);
+            mediaType = makeString("text/plain"_s, mediaType);
 
         if (shouldRemoveFragmentIdentifier(mediaType))
             url.removeFragmentIdentifier();

Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (292941 => 292942)


--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2022-04-16 19:28:05 UTC (rev 292941)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2022-04-16 20:31:36 UTC (rev 292942)
@@ -950,8 +950,7 @@
         GlobalFree(memObj);
         return 0;
     }
-    extension.insert("."_s, 0);
-    fsPath = fileSystemPathFromURLOrTitle(url, preferredTitle, extension, false);
+    fsPath = fileSystemPathFromURLOrTitle(url, preferredTitle, makeString('.', extension), false);
 
     if (fsPath.length() <= 0) {
         GlobalUnlock(memObj);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to