Diff
Modified: trunk/Source/WTF/ChangeLog (292944 => 292945)
--- trunk/Source/WTF/ChangeLog 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WTF/ChangeLog 2022-04-17 03:56:33 UTC (rev 292945)
@@ -1,5 +1,24 @@
2022-04-16 Chris Dumez <[email protected]>
+ Drop String::truncate() and use String::left() instead
+ https://bugs.webkit.org/show_bug.cgi?id=239412
+
+ Reviewed by Darin Adler.
+
+ String::truncate() and String::left() have identical behavior. The only difference is that truncate()
+ modifies the String in place (which is a bit confusing), while left() returns a new String, without
+ modifying the original. To simplify our API, I am dropping String::truncate().
+
+ * wtf/text/WTFString.cpp:
+ (WTF::String::truncate): Deleted.
+ * wtf/text/WTFString.h:
+ * wtf/unix/LanguageUnix.cpp:
+ (WTF::platformLanguage):
+ * wtf/win/LanguageWin.cpp:
+ (WTF::localeInfo):
+
+2022-04-16 Chris Dumez <[email protected]>
+
Replace complex String::insert() with a simplified makeStringByInserting() free function
https://bugs.webkit.org/show_bug.cgi?id=239370
Modified: trunk/Source/WTF/wtf/text/WTFString.cpp (292944 => 292945)
--- trunk/Source/WTF/wtf/text/WTFString.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WTF/wtf/text/WTFString.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -85,12 +85,6 @@
return m_impl->characterStartingAt(i);
}
-void String::truncate(unsigned position)
-{
- if (m_impl)
- m_impl = m_impl->substring(0, position);
-}
-
template<typename CharacterType> inline void String::removeInternal(const CharacterType* characters, unsigned position, unsigned lengthToRemove)
{
CharacterType* data;
Modified: trunk/Source/WTF/wtf/text/WTFString.h (292944 => 292945)
--- trunk/Source/WTF/wtf/text/WTFString.h 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2022-04-17 03:56:33 UTC (rev 292945)
@@ -196,9 +196,6 @@
String& replace(unsigned start, unsigned length, StringView replacement);
template<unsigned characterCount> String& replaceWithLiteral(UChar target, const char (&replacement)[characterCount]);
- // FIXME: This is identifical to left() and should probably be dropped.
- WTF_EXPORT_PRIVATE void truncate(unsigned length);
-
WTF_EXPORT_PRIVATE void remove(unsigned position, unsigned length = 1);
WTF_EXPORT_PRIVATE String substring(unsigned position, unsigned length = MaxLength) const;
Modified: trunk/Source/WTF/wtf/unix/LanguageUnix.cpp (292944 => 292945)
--- trunk/Source/WTF/wtf/unix/LanguageUnix.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WTF/wtf/unix/LanguageUnix.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -38,8 +38,7 @@
String normalizedDefault = localeDefault;
normalizedDefault.replace('_', '-');
- normalizedDefault.truncate(normalizedDefault.find('.'));
- return normalizedDefault;
+ return normalizedDefault.left(normalizedDefault.find('.'));
}
Vector<String> platformUserPreferredLanguages(ShouldMinimizeLanguages)
Modified: trunk/Source/WTF/wtf/win/LanguageWin.cpp (292944 => 292945)
--- trunk/Source/WTF/wtf/win/LanguageWin.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WTF/wtf/win/LanguageWin.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -51,8 +51,7 @@
if (localeName.isEmpty())
return fallback;
- localeName.truncate(localeName.length() - 1);
- return localeName;
+ return localeName.left(localeName.length() - 1);
}
static String platformLanguage()
Modified: trunk/Source/WebCore/ChangeLog (292944 => 292945)
--- trunk/Source/WebCore/ChangeLog 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/ChangeLog 2022-04-17 03:56:33 UTC (rev 292945)
@@ -1,3 +1,31 @@
+2022-04-16 Chris Dumez <[email protected]>
+
+ Drop String::truncate() and use String::left() instead
+ https://bugs.webkit.org/show_bug.cgi?id=239412
+
+ Reviewed by Darin Adler.
+
+ * Modules/highlight/AppHighlightStorage.cpp:
+ (WebCore::createAppHighlightRangeData):
+ * dom/FragmentDirectiveParser.cpp:
+ (WebCore::FragmentDirectiveParser::parseFragmentDirective):
+ * html/HTMLImageElement.cpp:
+ (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
+ * html/TextFieldInputType.cpp:
+ (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
+ * loader/FTPDirectoryParser.h:
+ (WebCore::ListResult::clear):
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::didBeginDocument):
+ * page/CaptionUserPreferencesMediaAF.cpp:
+ (WebCore::languageIdentifier):
+ * platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm:
+ (WebCore::contentTypesToCodecs):
+ * platform/text/hyphen/HyphenationLibHyphen.cpp:
+ (WebCore::scanDirectoryForDictionaries):
+ * platform/win/ClipboardUtilitiesWin.cpp:
+ (WebCore::extractURL):
+
2022-04-16 Wenson Hsieh <[email protected]>
[macOS] Image controls are editable and prevent drops in editable web views
Modified: trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp (292944 => 292945)
--- trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/Modules/highlight/AppHighlightStorage.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -203,8 +203,7 @@
static AppHighlightRangeData createAppHighlightRangeData(const StaticRange& range)
{
- auto text = plainText(range);
- text.truncate(textPreviewLength);
+ auto text = plainText(range).left(textPreviewLength);
auto identifier = createVersion4UUIDString();
return {
Modified: trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp (292944 => 292945)
--- trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/dom/FragmentDirectiveParser.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -100,9 +100,8 @@
ParsedTextDirective parsedTextDirective;
if (tokens.first().endsWith('-') && tokens.first().length() > 1) {
- tokens.first().truncate(tokens.first().length() - 2);
-
- if (auto prefix = WTF::URLParser::formURLDecode(tokens.takeFirst()))
+ auto takenFirstToken = tokens.takeFirst();
+ if (auto prefix = WTF::URLParser::formURLDecode(StringView(takenFirstToken).left(takenFirstToken.length() - 2)))
parsedTextDirective.prefix = WTFMove(*prefix);
else
LOG_WITH_STREAM(TextFragment, stream << " could not decode prefix ");
Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (292944 => 292945)
--- trunk/Source/WebCore/html/HTMLImageElement.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -191,6 +191,14 @@
downcast<RenderImage>(*renderer()).setImageDevicePixelRatio(m_imageDevicePixelRatio);
}
+static String extractMIMETypeFromTypeAttributeForLookup(const String& typeAttribute)
+{
+ auto semicolonIndex = typeAttribute.find(';');
+ if (semicolonIndex == notFound)
+ return stripLeadingAndTrailingHTMLSpaces(typeAttribute);
+ return StringView(typeAttribute).left(semicolonIndex).stripLeadingAndTrailingMatchedCharacters(isHTMLSpace<UChar>).toStringWithoutCopying();
+}
+
ImageCandidate HTMLImageElement::bestFitSourceFromPictureElement()
{
RefPtr picture = pictureElement();
@@ -210,9 +218,7 @@
auto& typeAttribute = source.attributeWithoutSynchronization(typeAttr);
if (!typeAttribute.isNull()) {
- String type = typeAttribute.string();
- type.truncate(type.find(';'));
- type = stripLeadingAndTrailingHTMLSpaces(type);
+ auto type = extractMIMETypeFromTypeAttributeForLookup(typeAttribute);
if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(type))
continue;
}
Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (292944 => 292945)
--- trunk/Source/WebCore/html/TextFieldInputType.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -620,14 +620,12 @@
unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;
// Truncate the inserted text to avoid violating the maxLength and other constraints.
+ // FIXME: This may cause a lot of String allocations in the worst case scenario.
String eventText = event.text();
unsigned textLength = eventText.length();
while (textLength > 0 && isHTMLLineBreak(eventText[textLength - 1]))
textLength--;
- eventText.truncate(textLength);
- eventText.replace("\r\n", " ");
- eventText.replace('\r', ' ');
- eventText.replace('\n', ' ');
+ eventText = eventText.left(textLength).replace("\r\n", " ").replace('\r', ' ').replace('\n', ' ');
event.setText(limitLength(eventText, appendableLength));
}
Modified: trunk/Source/WebCore/loader/FTPDirectoryParser.h (292944 => 292945)
--- trunk/Source/WebCore/loader/FTPDirectoryParser.h 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/loader/FTPDirectoryParser.h 2022-04-17 03:56:33 UTC (rev 292945)
@@ -130,7 +130,7 @@
filenameLength = 0;
linkname = nullptr;
linknameLength = 0;
- fileSize.truncate(0);
+ fileSize = { };
caseSensitive = false;
memset(&modifiedTime, 0, sizeof(FTPTime));
}
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (292944 => 292945)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -715,6 +715,14 @@
m_outgoingReferrer = url.strippedForUseAsReferrer();
}
+static String extractContentLanguageFromHeader(const String& header)
+{
+ auto commaIndex = header.find(',');
+ if (commaIndex == notFound)
+ return stripLeadingAndTrailingHTMLSpaces(header);
+ return StringView(header).left(commaIndex).stripLeadingAndTrailingMatchedCharacters(isHTMLSpace<UChar>).toString();
+}
+
void FrameLoader::didBeginDocument(bool dispatch)
{
m_needsClear = true;
@@ -757,9 +765,7 @@
String headerContentLanguage = m_documentLoader->response().httpHeaderField(HTTPHeaderName::ContentLanguage);
if (!headerContentLanguage.isEmpty()) {
- size_t commaIndex = headerContentLanguage.find(',');
- headerContentLanguage.truncate(commaIndex); // notFound == -1 == don't truncate
- headerContentLanguage = stripLeadingAndTrailingHTMLSpaces(headerContentLanguage);
+ headerContentLanguage = extractContentLanguageFromHeader(headerContentLanguage);
if (!headerContentLanguage.isEmpty())
m_frame.document()->setContentLanguage(headerContentLanguage);
}
Modified: trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp (292944 => 292945)
--- trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/page/CaptionUserPreferencesMediaAF.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -662,7 +662,7 @@
// Need 2U here to disambiguate String::operator[] from operator(NSString*, int)[] in a production build.
if (lowercaseLanguageCode.length() >= 3 && (lowercaseLanguageCode[2U] == '_' || lowercaseLanguageCode[2U] == '-'))
- lowercaseLanguageCode.truncate(2);
+ lowercaseLanguageCode = lowercaseLanguageCode.left(2);
return lowercaseLanguageCode;
}
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm (292944 => 292945)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm 2022-04-17 03:56:33 UTC (rev 292945)
@@ -45,12 +45,7 @@
for (auto& codecString : codecStrings) {
// https://tools.ietf.org/html/rfc6381
// Within a 'codecs' parameter value, "." is reserved as a hierarchy delimiter
- auto firstPeriod = codecString.find('.');
- if (firstPeriod != notFound)
- codecString.truncate(firstPeriod);
-
- auto codecIdentifier = FourCC::fromString(StringView { codecString }.left(4));
- if (codecIdentifier)
+ if (auto codecIdentifier = FourCC::fromString(StringView(codecString).left(codecString.find('.')).left(4)))
codecs.append(codecIdentifier.value());
}
}
Modified: trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp (292944 => 292945)
--- trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/platform/text/hyphen/HyphenationLibHyphen.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -79,16 +79,14 @@
filePath = FileSystem::stringFromFileSystemRepresentation(normalizedPath);
availableLocales.add(locale, Vector<String>()).iterator->value.append(filePath);
- String localeReplacingUnderscores = String(locale);
+ String localeReplacingUnderscores = locale;
localeReplacingUnderscores.replace('_', '-');
if (locale != localeReplacingUnderscores)
availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
size_t dividerPosition = localeReplacingUnderscores.find('-');
- if (dividerPosition != notFound) {
- localeReplacingUnderscores.truncate(dividerPosition);
- availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
- }
+ if (dividerPosition != notFound)
+ availableLocales.add(localeReplacingUnderscores.left(dividerPosition), Vector<String>()).iterator->value.append(filePath);
}
}
Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (292944 => 292945)
--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -119,15 +119,15 @@
return true;
}
-static String extractURL(const String &inURL, String* title)
+static String extractURL(const String& url, String* title)
{
- String url = ""
- int splitLoc = url.find('\n');
- if (splitLoc > 0) {
+ auto splitIndex = url.find('\n');
+ if (splitIndex != notFound) {
if (title)
- *title = url.substring(splitLoc+1);
- url.truncate(splitLoc);
- } else if (title)
+ *title = url.substring(splitIndex + 1);
+ return url.left(splitIndex);
+ }
+ if (title)
*title = url;
return url;
}
Modified: trunk/Source/WebKit/ChangeLog (292944 => 292945)
--- trunk/Source/WebKit/ChangeLog 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebKit/ChangeLog 2022-04-17 03:56:33 UTC (rev 292945)
@@ -1,3 +1,13 @@
+2022-04-16 Chris Dumez <[email protected]>
+
+ Drop String::truncate() and use String::left() instead
+ https://bugs.webkit.org/show_bug.cgi?id=239412
+
+ Reviewed by Darin Adler.
+
+ * Shared/mac/AuxiliaryProcessMac.mm:
+ (WebKit::getUserDirectorySuffix):
+
2022-04-15 Chris Dumez <[email protected]>
Leverage StringView in more places to avoid some String allocations
Modified: trunk/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm (292944 => 292945)
--- trunk/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm 2022-04-17 03:56:33 UTC (rev 292945)
@@ -636,10 +636,7 @@
auto userDirectorySuffix = parameters.extraInitializationData.find<HashTranslatorASCIILiteral>("user-directory-suffix"_s);
if (userDirectorySuffix != parameters.extraInitializationData.end()) {
String suffix = userDirectorySuffix->value;
- auto firstPathSeparator = suffix.find('/');
- if (firstPathSeparator != notFound)
- suffix.truncate(firstPathSeparator);
- return suffix;
+ return suffix.left(suffix.find('/'));
}
String clientIdentifier = codeSigningIdentifier(parameters.connectionIdentifier.xpcConnection.get());
Modified: trunk/Source/WebKitLegacy/win/ChangeLog (292944 => 292945)
--- trunk/Source/WebKitLegacy/win/ChangeLog 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebKitLegacy/win/ChangeLog 2022-04-17 03:56:33 UTC (rev 292945)
@@ -1,3 +1,13 @@
+2022-04-16 Chris Dumez <[email protected]>
+
+ Drop String::truncate() and use String::left() instead
+ https://bugs.webkit.org/show_bug.cgi?id=239412
+
+ Reviewed by Darin Adler.
+
+ * WebDownloadCFNet.cpp:
+ (WebDownload::initToResumeWithBundle):
+
2022-04-15 Yusuke Suzuki <[email protected]>
[JSC] Remove VM& parameter from structure related code including jsDyamicCast
Modified: trunk/Source/WebKitLegacy/win/WebDownloadCFNet.cpp (292944 => 292945)
--- trunk/Source/WebKitLegacy/win/WebDownloadCFNet.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Source/WebKitLegacy/win/WebDownloadCFNet.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -192,8 +192,7 @@
// Attempt to remove the ".download" extension from the bundle for the final file destination
// Failing that, we clear m_destination and will ask the delegate later once the download starts
if (m_bundlePath.endsWithIgnoringASCIICase(DownloadBundle::fileExtension())) {
- m_destination = m_bundlePath.isolatedCopy();
- m_destination.truncate(m_destination.length() - DownloadBundle::fileExtension().length());
+ m_destination = StringView(m_bundlePath).left(m_destination.length() - DownloadBundle::fileExtension().length()).toString().isolatedCopy();
} else
m_destination = String();
Modified: trunk/Tools/ChangeLog (292944 => 292945)
--- trunk/Tools/ChangeLog 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Tools/ChangeLog 2022-04-17 03:56:33 UTC (rev 292945)
@@ -1,3 +1,13 @@
+2022-04-16 Chris Dumez <[email protected]>
+
+ Drop String::truncate() and use String::left() instead
+ https://bugs.webkit.org/show_bug.cgi?id=239412
+
+ Reviewed by Darin Adler.
+
+ * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+ (WTR::InjectedBundlePage::willAddMessageToConsole):
+
2022-04-16 Wenson Hsieh <[email protected]>
[macOS] Image controls are editable and prevent drops in editable web views
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp (292944 => 292945)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp 2022-04-17 03:13:03 UTC (rev 292944)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp 2022-04-17 03:56:33 UTC (rev 292945)
@@ -51,6 +51,7 @@
#include <wtf/RunLoop.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
+#include <wtf/unicode/CharacterNames.h>
#if USE(CF)
#include <wtf/text/cf/StringConcatenateCF.h>
@@ -1339,9 +1340,7 @@
return;
auto messageString = toWTFString(message);
- size_t nullCharPos = messageString.find(UChar(0));
- if (nullCharPos != WTF::notFound)
- messageString.truncate(nullCharPos);
+ messageString = messageString.left(messageString.find(nullCharacter));
size_t fileProtocolStart = messageString.find("file://");
if (fileProtocolStart != WTF::notFound) {