Diff
Modified: trunk/Source/WTF/ChangeLog (292950 => 292951)
--- trunk/Source/WTF/ChangeLog 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WTF/ChangeLog 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1,3 +1,17 @@
+2022-04-17 Chris Dumez <cdu...@apple.com>
+
+ Leverage StringView in more places
+ https://bugs.webkit.org/show_bug.cgi?id=239426
+
+ Reviewed by Sam Weinig.
+
+ Leverage StringView in more places, to reduce the number of String allocations.
+
+ * wtf/text/StringImpl.cpp:
+ * wtf/text/StringImpl.h:
+ (WTF::isNotSpaceOrNewline):
+ * wtf/text/WTFString.h:
+
2022-04-16 Chris Dumez <cdu...@apple.com>
Drop String::truncate() and use String::left() instead
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (292950 => 292951)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -835,13 +835,6 @@
return charactersToFloat(characters16(), m_length, ok);
}
-size_t StringImpl::find(CodeUnitMatchFunction matchFunction, unsigned start)
-{
- if (is8Bit())
- return WTF::find(characters8(), m_length, matchFunction, start);
- return WTF::find(characters16(), m_length, matchFunction, start);
-}
-
size_t StringImpl::find(const LChar* matchString, unsigned start)
{
// Check for null or empty string to match against
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (292950 => 292951)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -430,7 +430,8 @@
size_t find(LChar character, unsigned start = 0);
size_t find(char character, unsigned start = 0);
size_t find(UChar character, unsigned start = 0);
- WTF_EXPORT_PRIVATE size_t find(CodeUnitMatchFunction, unsigned start = 0);
+ template<typename CodeUnitMatchFunction, std::enable_if_t<std::is_invocable_r_v<bool, CodeUnitMatchFunction, UChar>>* = nullptr>
+ size_t find(CodeUnitMatchFunction, unsigned start = 0);
WTF_EXPORT_PRIVATE size_t find(const LChar*, unsigned start = 0);
WTF_EXPORT_PRIVATE size_t find(StringView);
WTF_EXPORT_PRIVATE size_t find(StringView, unsigned start);
@@ -600,6 +601,7 @@
// FIXME: Should rename this to make clear it uses the Unicode definition of whitespace.
// Most WebKit callers don't want that would use isASCIISpace or isHTMLSpace instead.
bool isSpaceOrNewline(UChar32);
+bool isNotSpaceOrNewline(UChar32);
template<typename CharacterType> unsigned lengthOfNullTerminatedString(const CharacterType*);
@@ -704,6 +706,14 @@
return WTF::find(characters16(), m_length, character, start);
}
+template<typename CodeUnitMatchFunction, std::enable_if_t<std::is_invocable_r_v<bool, CodeUnitMatchFunction, UChar>>*>
+size_t StringImpl::find(CodeUnitMatchFunction matchFunction, unsigned start)
+{
+ if (is8Bit())
+ return WTF::find(characters8(), m_length, matchFunction, start);
+ return WTF::find(characters16(), m_length, matchFunction, start);
+}
+
template<size_t inlineCapacity> inline bool equalIgnoringNullity(const Vector<UChar, inlineCapacity>& a, StringImpl* b)
{
return equalIgnoringNullity(a.data(), a.size(), b);
@@ -754,6 +764,11 @@
return isLatin1(character) ? isASCIISpace(character) : u_charDirection(character) == U_WHITE_SPACE_NEUTRAL;
}
+inline bool isNotSpaceOrNewline(UChar32 character)
+{
+ return !isSpaceOrNewline(character);
+}
+
template<typename CharacterType> inline unsigned lengthOfNullTerminatedString(const CharacterType* string)
{
ASSERT(string);
@@ -1314,3 +1329,5 @@
using WTF::StaticStringImpl;
using WTF::StringImpl;
using WTF::equal;
+using WTF::isNotSpaceOrNewline;
+using WTF::isSpaceOrNewline;
Modified: trunk/Source/WTF/wtf/text/WTFString.h (292950 => 292951)
--- trunk/Source/WTF/wtf/text/WTFString.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -161,6 +161,7 @@
size_t findIgnoringASCIICase(StringView) const;
size_t findIgnoringASCIICase(StringView, unsigned start) const;
+ template<typename CodeUnitMatchFunction, std::enable_if_t<std::is_invocable_r_v<bool, CodeUnitMatchFunction, UChar>>* = nullptr>
size_t find(CodeUnitMatchFunction matchFunction, unsigned start = 0) const { return m_impl ? m_impl->find(matchFunction, start) : notFound; }
size_t find(const LChar* string, unsigned start = 0) const { return m_impl ? m_impl->find(string, start) : notFound; }
@@ -640,7 +641,6 @@
using WTF::equal;
using WTF::find;
using WTF::isAllSpecialCharacters;
-using WTF::isSpaceOrNewline;
using WTF::reverseFind;
#include <wtf/text/AtomString.h>
Modified: trunk/Source/WebCore/ChangeLog (292950 => 292951)
--- trunk/Source/WebCore/ChangeLog 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/ChangeLog 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1,3 +1,82 @@
+2022-04-17 Chris Dumez <cdu...@apple.com>
+
+ Leverage StringView in more places
+ https://bugs.webkit.org/show_bug.cgi?id=239426
+
+ Reviewed by Sam Weinig.
+
+ Leverage StringView in more places, to reduce the number of String allocations.
+
+ * Modules/applicationmanifest/ApplicationManifestParser.cpp:
+ (WebCore::ApplicationManifestParser::parseDisplay):
+ (WebCore::ApplicationManifestParser::parseIcons):
+ * Modules/indexeddb/server/SQLiteIDBCursor.cpp:
+ (WebCore::IDBServer::SQLiteIDBCursor::createSQLiteStatement):
+ * Modules/indexeddb/server/SQLiteIDBCursor.h:
+ * Modules/webdatabase/Database.cpp:
+ (WebCore::setTextValueInDatabase):
+ (WebCore::retrieveTextResultFromDatabase):
+ * accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:
+ (-[WebAccessibilityObjectWrapper determineIsAccessibilityElement]):
+ (appendStringToResult): Deleted.
+ (accessibleElementsForObjects): Deleted.
+ (rendererForView): Deleted.
+ * css/parser/MediaQueryParser.h:
+ (WebCore::MediaQueryParser::MediaQueryData::setMediaType):
+ * editing/Editor.cpp:
+ (WebCore::Editor::transpose):
+ * editing/FrameSelection.cpp:
+ (WebCore::FrameSelection::debugRenderer const):
+ * html/MediaFragmentURIParser.cpp:
+ (WebCore::collectFraction):
+ (WebCore::MediaFragmentURIParser::parseNPTTime):
+ * html/StepRange.cpp:
+ (WebCore::StepRange::parseStep):
+ * html/StepRange.h:
+ * html/parser/HTMLParserIdioms.cpp:
+ (WebCore::parseToDecimalForNumberType):
+ (WebCore::parseToDoubleForNumberType):
+ * html/parser/HTMLParserIdioms.h:
+ * inspector/agents/InspectorDOMAgent.cpp:
+ (WebCore::InspectorDOMAgent::setAttributesAsText):
+ * layout/formattingContexts/inline/InlineItemsBuilder.cpp:
+ (WebCore::Layout::replaceNonPreservedNewLineCharactersAndAppend):
+ * layout/integration/LayoutIntegrationCoverage.cpp:
+ (WebCore::LayoutIntegration::printTextForSubtree):
+ * page/TextIndicator.cpp:
+ (WebCore::containsOnlyWhiteSpaceText):
+ * platform/Decimal.cpp:
+ (WebCore::Decimal::fromString):
+ * platform/Decimal.h:
+ * platform/network/CacheValidation.cpp:
+ (WebCore::parseCacheHeader):
+ (WebCore::parseCacheControlDirectives):
+ * platform/network/HTTPParsers.cpp:
+ (WebCore::filenameFromHTTPContentDisposition):
+ * platform/network/HTTPParsers.h:
+ * platform/network/MIMEHeader.cpp:
+ (WebCore::retrieveKeyValuePairs):
+ (WebCore::MIMEHeader::parseContentTransferEncoding):
+ * platform/network/MIMEHeader.h:
+ * platform/network/ParsedContentType.cpp:
+ (WebCore::ParsedContentType::setContentType):
+ * platform/network/ResourceResponseBase.cpp:
+ (WebCore::ResourceResponseBase::isAttachment const):
+ (WebCore::ResourceResponseBase::isAttachmentWithFilename const):
+ * platform/network/curl/ResourceResponseCurl.cpp:
+ (WebCore::ResourceResponse::platformSuggestedFilename const):
+ * platform/sql/SQLiteDatabase.cpp:
+ (WebCore::SQLiteDatabase::executeCommandSlow):
+ (WebCore::SQLiteDatabase::clearAllTables):
+ (WebCore::SQLiteDatabase::prepareStatementSlow):
+ (WebCore::SQLiteDatabase::prepareHeapStatementSlow):
+ * platform/sql/SQLiteDatabase.h:
+ * platform/xr/PlatformXR.h:
+ (PlatformXR::parseSessionFeatureDescriptor):
+ * svg/SVGAnimationElement.cpp:
+ (WebCore::parseKeyTimes):
+ (WebCore::SVGAnimationElement::parseAttribute):
+
2022-04-17 Lauro Moura <lmo...@igalia.com>
Unreviewed, non-unified build fixes after 249632@main
Modified: trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp (292950 => 292951)
--- trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/Modules/applicationmanifest/ApplicationManifestParser.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -145,7 +145,7 @@
return ApplicationManifest::Display::Browser;
}
- stringValue = stringValue.stripWhiteSpace().convertToASCIILowercase();
+ stringValue = StringView(stringValue).stripWhiteSpace().convertToASCIILowercase();
if (stringValue == "fullscreen")
return ApplicationManifest::Display::Fullscreen;
@@ -230,19 +230,17 @@
purposes.add(ApplicationManifest::Icon::Purpose::Any);
currentIcon.purposes = purposes;
} else {
- purposeStringValue = purposeStringValue.stripWhiteSpace().convertToASCIILowercase();
- Vector<String> keywords = purposeStringValue.splitAllowingEmptyEntries(" ");
-
- for (const auto& keyword : keywords) {
- if (keyword == "monochrome")
+ for (auto keyword : StringView(purposeStringValue).stripWhiteSpace().splitAllowingEmptyEntries(' ')) {
+ if (equalLettersIgnoringASCIICase(keyword, "monochrome"))
purposes.add(ApplicationManifest::Icon::Purpose::Monochrome);
- else if (keyword == "maskable")
+ else if (equalLettersIgnoringASCIICase(keyword, "maskable"))
purposes.add(ApplicationManifest::Icon::Purpose::Maskable);
- else if (keyword == "any")
+ else if (equalLettersIgnoringASCIICase(keyword, "any"))
purposes.add(ApplicationManifest::Icon::Purpose::Any);
else
logDeveloperWarning(makeString("\""_s, purposeStringValue, "\" is not a valid purpose."_s));
}
+
if (purposes.isEmpty())
continue;
Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp (292950 => 292951)
--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -181,7 +181,7 @@
return createSQLiteStatement(sql);
}
-bool SQLiteIDBCursor::createSQLiteStatement(const String& sql)
+bool SQLiteIDBCursor::createSQLiteStatement(StringView sql)
{
LOG(IndexedDB, "Creating cursor with SQL query: \"%s\"", sql.utf8().data());
Modified: trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h (292950 => 292951)
--- trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/Modules/indexeddb/server/SQLiteIDBCursor.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -81,7 +81,7 @@
private:
bool establishStatement();
- bool createSQLiteStatement(const String& sql);
+ bool createSQLiteStatement(StringView sql);
bool bindArguments();
bool resetAndRebindPreIndexStatementIfNecessary();
Modified: trunk/Source/WebCore/Modules/webdatabase/Database.cpp (292950 => 292951)
--- trunk/Source/WebCore/Modules/webdatabase/Database.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/Modules/webdatabase/Database.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -112,11 +112,11 @@
return makeString(message, " (", sqliteErrorCode, ' ', sqliteErrorMessage, ')');
}
-static bool setTextValueInDatabase(SQLiteDatabase& db, const String& query, const String& value)
+static bool setTextValueInDatabase(SQLiteDatabase& db, StringView query, const String& value)
{
auto statement = db.prepareStatementSlow(query);
if (!statement) {
- LOG_ERROR("Failed to prepare statement to set value in database (%s)", query.ascii().data());
+ LOG_ERROR("Failed to prepare statement to set value in database (%s)", query.utf8().data());
return false;
}
@@ -123,7 +123,7 @@
statement->bindText(1, value);
if (statement->step() != SQLITE_DONE) {
- LOG_ERROR("Failed to step statement to set value in database (%s)", query.ascii().data());
+ LOG_ERROR("Failed to step statement to set value in database (%s)", query.utf8().data());
return false;
}
@@ -130,11 +130,11 @@
return true;
}
-static bool retrieveTextResultFromDatabase(SQLiteDatabase& db, const String& query, String& resultString)
+static bool retrieveTextResultFromDatabase(SQLiteDatabase& db, StringView query, String& resultString)
{
auto statement = db.prepareStatementSlow(query);
if (!statement) {
- LOG_ERROR("Error (%i) preparing statement to read text result from database (%s)", statement.error(), query.ascii().data());
+ LOG_ERROR("Error (%i) preparing statement to read text result from database (%s)", statement.error(), query.utf8().data());
return false;
}
@@ -148,7 +148,7 @@
return true;
}
- LOG_ERROR("Error (%i) reading text result from database (%s)", result, query.ascii().data());
+ LOG_ERROR("Error (%i) reading text result from database (%s)", result, query.utf8().data());
return false;
}
Modified: trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm (292950 => 292951)
--- trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1114,7 +1114,7 @@
// https://bugs.webkit.org/show_bug.cgi?id=223492
return self.axBackingObject->isKeyboardFocusable()
&& [self accessibilityElementCount] == 0
- && self.axBackingObject->descriptionAttributeValue().stripWhiteSpace().length() > 0;
+ && self.axBackingObject->descriptionAttributeValue().find(isNotSpaceOrNewline) != notFound;
case AccessibilityRole::Ignored:
case AccessibilityRole::Presentational:
case AccessibilityRole::Unknown:
Modified: trunk/Source/WebCore/css/parser/MediaQueryParser.h (292950 => 292951)
--- trunk/Source/WebCore/css/parser/MediaQueryParser.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/css/parser/MediaQueryParser.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -93,7 +93,7 @@
void addExpression(CSSParserTokenRange&);
bool lastExpressionValid();
void removeLastExpression();
- void setMediaType(const String& mediaType) { m_mediaType = mediaType; }
+ void setMediaType(String&& mediaType) { m_mediaType = WTFMove(mediaType); }
MediaQuery::Restrictor restrictor() const { return m_restrictor; }
Vector<MediaQueryExpression>& expressions() { return m_expressions; }
Modified: trunk/Source/WebCore/editing/Editor.cpp (292950 => 292951)
--- trunk/Source/WebCore/editing/Editor.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/editing/Editor.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -3221,8 +3221,10 @@
String text = plainText(*range);
if (text.length() != 2)
return;
- String transposed = text.right(1) + text.left(1);
+ // FIXME: This likely won't work with graphemes.
+ String transposed = makeString(text[1], text[0]);
+
// Select the two characters.
if (newSelection != m_document.selection().selection()) {
if (!m_document.selection().shouldChangeSelection(newSelection))
Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (292950 => 292951)
--- trunk/Source/WebCore/editing/FrameSelection.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1902,15 +1902,15 @@
caret = pos;
} else if (pos - mid < 0) {
// too few characters to left
- show = text.left(max - 3) + "...";
+ show = makeString(StringView(text).left(max - 3), "...");
caret = pos;
} else if (pos - mid >= 0 && pos + mid <= textLength) {
// enough characters on each side
- show = "..." + text.substring(pos - mid + 3, max - 6) + "...";
+ show = makeString("...", StringView(text).substring(pos - mid + 3, max - 6), "...");
caret = mid;
} else {
// too few characters on right
- show = "..." + text.right(max - 3);
+ show = makeString("...", StringView(text).right(max - 3));
caret = pos - (textLength - show.length());
}
Modified: trunk/Source/WebCore/html/MediaFragmentURIParser.cpp (292950 => 292951)
--- trunk/Source/WebCore/html/MediaFragmentURIParser.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/html/MediaFragmentURIParser.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -55,19 +55,17 @@
return digits.toString();
}
-static String collectFraction(const LChar* input, unsigned length, unsigned& position)
+static StringView collectFraction(const LChar* input, unsigned length, unsigned& position)
{
- StringBuilder digits;
-
// http://www.ietf.org/rfc/rfc2326.txt
// [ "." *DIGIT ]
if (input[position] != '.')
- return String();
+ return { };
- digits.append(input[position++]);
+ unsigned start = position++;
while (position < length && isASCIIDigit(input[position]))
- digits.append(input[position++]);
- return digits.toString();
+ ++position;
+ return StringView { input + start, position - start };
}
MediaFragmentURIParser::MediaFragmentURIParser(const URL& url)
@@ -270,8 +268,9 @@
if (timeString[offset] == '.') {
if (offset == length)
return true;
- String digits = collectFraction(timeString, length, offset);
- fraction = MediaTime::createWithDouble(digits.toDouble());
+ auto digits = collectFraction(timeString, length, offset);
+ bool isValid;
+ fraction = MediaTime::createWithDouble(digits.toDouble(isValid));
time = MediaTime::createWithDouble(value1) + fraction;
return true;
}
@@ -308,8 +307,10 @@
value1 = 0;
}
- if (offset < length && timeString[offset] == '.')
- fraction = MediaTime::createWithDouble(collectFraction(timeString, length, offset).toDouble());
+ if (offset < length && timeString[offset] == '.') {
+ bool isValid;
+ fraction = MediaTime::createWithDouble(collectFraction(timeString, length, offset).toDouble(isValid));
+ }
time = MediaTime::createWithDouble((value1 * secondsPerHour) + (value2 * secondsPerMinute) + value3) + fraction;
return true;
Modified: trunk/Source/WebCore/html/StepRange.cpp (292950 => 292951)
--- trunk/Source/WebCore/html/StepRange.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/html/StepRange.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -95,7 +95,7 @@
return clampedValue;
}
-Decimal StepRange::parseStep(AnyStepHandling anyStepHandling, const StepDescription& stepDescription, const String& stepString)
+Decimal StepRange::parseStep(AnyStepHandling anyStepHandling, const StepDescription& stepDescription, StringView stepString)
{
if (stepString.isEmpty())
return stepDescription.defaultValue();
Modified: trunk/Source/WebCore/html/StepRange.h (292950 => 292951)
--- trunk/Source/WebCore/html/StepRange.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/html/StepRange.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -74,7 +74,7 @@
Decimal maximum() const { return m_maximum; }
Decimal minimum() const { return m_minimum; }
Decimal stepSnappedMaximum() const;
- static Decimal parseStep(AnyStepHandling, const StepDescription&, const String&);
+ static Decimal parseStep(AnyStepHandling, const StepDescription&, StringView);
Decimal step() const { return m_step; }
Decimal stepBase() const { return m_stepBase; }
int stepScaleFactor() const { return m_stepDescription.stepScaleFactor; }
Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp (292950 => 292951)
--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -92,9 +92,11 @@
return String::number(number);
}
-Decimal parseToDecimalForNumberType(const String& string, const Decimal& fallbackValue)
+Decimal parseToDecimalForNumberType(StringView string, const Decimal& fallbackValue)
{
// See HTML5 2.5.4.3 `Real numbers.' and parseToDoubleForNumberType
+ if (string.isEmpty())
+ return fallbackValue;
// String::toDouble() accepts leading + and whitespace characters, which are not valid here.
const UChar firstCharacter = string[0];
@@ -116,14 +118,16 @@
return value.isZero() ? Decimal(0) : value;
}
-Decimal parseToDecimalForNumberType(const String& string)
+Decimal parseToDecimalForNumberType(StringView string)
{
return parseToDecimalForNumberType(string, Decimal::nan());
}
-double parseToDoubleForNumberType(const String& string, double fallbackValue)
+double parseToDoubleForNumberType(StringView string, double fallbackValue)
{
// See HTML5 2.5.4.3 `Real numbers.'
+ if (string.isEmpty())
+ return fallbackValue;
// String::toDouble() accepts leading + and whitespace characters, which are not valid here.
UChar firstCharacter = string[0];
@@ -134,11 +138,11 @@
return fallbackValue;
bool valid = false;
- double value = string.toDouble(&valid);
+ double value = string.toDouble(valid);
if (!valid)
return fallbackValue;
- // NaN and infinity are considered valid by String::toDouble, but not valid here.
+ // NaN and infinity are considered valid by StringView::toDouble, but not valid here.
if (!std::isfinite(value))
return fallbackValue;
@@ -151,7 +155,7 @@
return value ? value : 0;
}
-double parseToDoubleForNumberType(const String& string)
+double parseToDoubleForNumberType(StringView string)
{
return parseToDoubleForNumberType(string, std::numeric_limits<double>::quiet_NaN());
}
Modified: trunk/Source/WebCore/html/parser/HTMLParserIdioms.h (292950 => 292951)
--- trunk/Source/WebCore/html/parser/HTMLParserIdioms.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/html/parser/HTMLParserIdioms.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -54,10 +54,10 @@
// Convert the specified string to a decimal/double. If the conversion fails, the return value is fallback value or NaN if not specified.
// Leading or trailing illegal characters cause failure, as does passing an empty string.
// The double* parameter may be 0 to check if the string can be parsed without getting the result.
-Decimal parseToDecimalForNumberType(const String&);
-Decimal parseToDecimalForNumberType(const String&, const Decimal& fallbackValue);
-double parseToDoubleForNumberType(const String&);
-double parseToDoubleForNumberType(const String&, double fallbackValue);
+Decimal parseToDecimalForNumberType(StringView);
+Decimal parseToDecimalForNumberType(StringView, const Decimal& fallbackValue);
+double parseToDoubleForNumberType(StringView);
+double parseToDoubleForNumberType(StringView, double fallbackValue);
// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-integers
enum class HTMLIntegerParsingError { NegativeOverflow, PositiveOverflow, Other };
Modified: trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp (292950 => 292951)
--- trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -758,7 +758,7 @@
return makeUnexpected(errorString);
}
- if (!foundOriginalAttribute && !name.stripWhiteSpace().isEmpty()) {
+ if (!foundOriginalAttribute && name.find(isNotSpaceOrNewline) != notFound) {
if (!m_domEditor->removeAttribute(*element, name, errorString))
return makeUnexpected(errorString);
}
Modified: trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp (292950 => 292951)
--- trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/layout/formattingContexts/inline/InlineItemsBuilder.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -163,12 +163,12 @@
continue;
if (nonReplacedContentStartPosition < startPosition)
- paragraphContentBuilder.append(textContent.substring(nonReplacedContentStartPosition, startPosition - nonReplacedContentStartPosition));
+ paragraphContentBuilder.append(StringView(textContent).substring(nonReplacedContentStartPosition, startPosition - nonReplacedContentStartPosition));
paragraphContentBuilder.append(space);
nonReplacedContentStartPosition = position;
}
if (nonReplacedContentStartPosition < contentLength)
- paragraphContentBuilder.append(textContent.right(contentLength - nonReplacedContentStartPosition));
+ paragraphContentBuilder.append(StringView(textContent).right(contentLength - nonReplacedContentStartPosition));
}
struct BidiContext {
Modified: trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp (292950 => 292951)
--- trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/layout/integration/LayoutIntegrationCoverage.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -219,10 +219,10 @@
for (auto& child : childrenOfType<RenderObject>(downcast<RenderElement>(renderer))) {
if (is<RenderText>(child)) {
String text = downcast<RenderText>(child).text();
- text = text.stripWhiteSpace();
- auto len = std::min(charactersLeft, text.length());
- stream << text.left(len);
- charactersLeft -= len;
+ auto textView = StringView(text).stripWhiteSpace();
+ auto length = std::min(charactersLeft, textView.length());
+ stream << textView.left(length);
+ charactersLeft -= length;
continue;
}
printTextForSubtree(downcast<RenderElement>(child), charactersLeft, stream);
Modified: trunk/Source/WebCore/page/TextIndicator.cpp (292950 => 292951)
--- trunk/Source/WebCore/page/TextIndicator.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/page/TextIndicator.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -228,7 +228,7 @@
if (!is<RenderText>(node.renderer()))
return false;
}
- return plainTextReplacingNoBreakSpace(range).stripWhiteSpace().isEmpty();
+ return plainTextReplacingNoBreakSpace(range).find(isNotSpaceOrNewline) == notFound;
}
static bool initializeIndicator(TextIndicatorData& data, Frame& frame, const SimpleRange& range, FloatSize margin, bool indicatesCurrentSelection)
Modified: trunk/Source/WebCore/platform/Decimal.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/Decimal.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/Decimal.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -693,7 +693,7 @@
return nan();
}
-Decimal Decimal::fromString(const String& str)
+Decimal Decimal::fromString(StringView str)
{
int exponent = 0;
Sign exponentSign = Positive;
Modified: trunk/Source/WebCore/platform/Decimal.h (292950 => 292951)
--- trunk/Source/WebCore/platform/Decimal.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/Decimal.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -149,7 +149,7 @@
// exponent-marker ::= 'e' | 'E'
// digit ::= '0' | '1' | ... | '9'
// Note: fromString doesn't support "infinity" and "nan".
- static Decimal fromString(const String&);
+ static Decimal fromString(StringView);
static Decimal infinity(Sign);
static Decimal nan();
static Decimal zero(Sign);
Modified: trunk/Source/WebCore/platform/network/CacheValidation.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/CacheValidation.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/CacheValidation.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -213,12 +213,12 @@
return string.left(string.find(isCacheHeaderSeparator));
}
-static Vector<std::pair<String, String>> parseCacheHeader(const String& header)
+static Vector<std::pair<StringView, StringView>> parseCacheHeader(StringView safeHeader)
{
- Vector<std::pair<String, String>> result;
+ ASSERT(safeHeader.find(isControlCharacterOrSpace) == notFound);
- String safeHeaderString = header.removeCharacters(isControlCharacterOrSpace);
- StringView safeHeader = safeHeaderString;
+ Vector<std::pair<StringView, StringView>> result;
+
unsigned max = safeHeader.length();
unsigned pos = 0;
while (pos < max) {
@@ -226,30 +226,30 @@
size_t nextEqualSignPosition = safeHeader.find('=', pos);
if (nextEqualSignPosition == notFound && nextCommaPosition == notFound) {
// Add last directive to map with empty string as value
- result.append({ trimToNextSeparator(safeHeader.substring(pos, max - pos)).toString(), emptyString() });
+ result.append({ trimToNextSeparator(safeHeader.substring(pos, max - pos)), emptyString() });
return result;
}
if (nextCommaPosition != notFound && (nextCommaPosition < nextEqualSignPosition || nextEqualSignPosition == notFound)) {
// Add directive to map with empty string as value
- result.append({ trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos)).toString(), emptyString() });
+ result.append({ trimToNextSeparator(safeHeader.substring(pos, nextCommaPosition - pos)), emptyString() });
pos += nextCommaPosition - pos + 1;
continue;
}
// Get directive name, parse right hand side of equal sign, then add to map
- String directive = trimToNextSeparator(safeHeader.substring(pos, nextEqualSignPosition - pos)).toString();
+ StringView directive = trimToNextSeparator(safeHeader.substring(pos, nextEqualSignPosition - pos));
pos += nextEqualSignPosition - pos + 1;
StringView value = safeHeader.substring(pos, max - pos);
- if (value[0] == '"') {
+ if (value.startsWith('"')) {
// The value is a quoted string
size_t nextDoubleQuotePosition = value.find('"', 1);
if (nextDoubleQuotePosition == notFound) {
// Parse error; just use the rest as the value
- result.append({ directive, trimToNextSeparator(value.substring(1)).toString() });
+ result.append({ directive, trimToNextSeparator(value.substring(1)) });
return result;
}
// Store the value as a quoted string without quotes
- result.append({ directive, value.substring(1, nextDoubleQuotePosition - 1).toString() });
+ result.append({ directive, value.substring(1, nextDoubleQuotePosition - 1) });
pos += (safeHeader.find('"', pos) - pos) + nextDoubleQuotePosition + 1;
// Move past next comma, if there is one
size_t nextCommaPosition2 = safeHeader.find(',', pos);
@@ -262,11 +262,11 @@
size_t nextCommaPosition2 = value.find(',');
if (nextCommaPosition2 == notFound) {
// The rest is the value; no change to value needed
- result.append({ directive, trimToNextSeparator(value).toString() });
+ result.append({ directive, trimToNextSeparator(value) });
return result;
}
// The value is delimited by the next comma
- result.append({ directive, trimToNextSeparator(value.left(nextCommaPosition2)).toString() });
+ result.append({ directive, trimToNextSeparator(value.left(nextCommaPosition2)) });
pos += (safeHeader.find(',', pos) - pos) + 1;
}
return result;
@@ -278,7 +278,8 @@
String cacheControlValue = headers.get(HTTPHeaderName::CacheControl);
if (!cacheControlValue.isEmpty()) {
- auto directives = parseCacheHeader(cacheControlValue);
+ auto safeHeaderString = cacheControlValue.removeCharacters(isControlCharacterOrSpace);
+ auto directives = parseCacheHeader(safeHeaderString);
size_t directivesSize = directives.size();
for (size_t i = 0; i < directivesSize; ++i) {
@@ -297,7 +298,7 @@
continue;
}
bool ok;
- double maxAge = directives[i].second.toDouble(&ok);
+ double maxAge = directives[i].second.toDouble(ok);
if (ok)
result.maxAge = Seconds { maxAge };
} else if (equalLettersIgnoringASCIICase(directives[i].first, "max-stale")) {
@@ -312,7 +313,7 @@
continue;
}
bool ok;
- double maxStale = directives[i].second.toDouble(&ok);
+ double maxStale = directives[i].second.toDouble(ok);
if (ok)
result.maxStale = Seconds { maxStale };
} else if (equalLettersIgnoringASCIICase(directives[i].first, "immutable")) {
@@ -323,7 +324,7 @@
continue;
}
bool ok;
- double staleWhileRevalidate = directives[i].second.toDouble(&ok);
+ double staleWhileRevalidate = directives[i].second.toDouble(ok);
if (ok)
result.staleWhileRevalidate = Seconds { staleWhileRevalidate };
}
Modified: trunk/Source/WebCore/platform/network/HTTPParsers.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/HTTPParsers.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -331,7 +331,7 @@
// that arises from quoted-string, nor does this function properly unquote
// attribute values. Further this function appears to process parameter names
// in a case-sensitive manner. (There are likely other bugs as well.)
-String filenameFromHTTPContentDisposition(StringView value)
+StringView filenameFromHTTPContentDisposition(StringView value)
{
for (auto keyValuePair : value.split(';')) {
size_t valueStartPos = keyValuePair.find('=');
@@ -349,7 +349,7 @@
if (value.length() > 1 && value[0] == '\"')
value = value.substring(1, value.length() - 2);
- return value.toString();
+ return value;
}
return String();
Modified: trunk/Source/WebCore/platform/network/HTTPParsers.h (292950 => 292951)
--- trunk/Source/WebCore/platform/network/HTTPParsers.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -79,7 +79,7 @@
bool isValidHTTPToken(const String&);
bool isValidHTTPToken(StringView);
std::optional<WallTime> parseHTTPDate(const String&);
-String filenameFromHTTPContentDisposition(StringView);
+StringView filenameFromHTTPContentDisposition(StringView);
WEBCORE_EXPORT String extractMIMETypeFromMediaType(const String&);
StringView extractCharsetFromMediaType(StringView);
XSSProtectionDisposition parseXSSProtectionHeader(const String& header, String& failureReason, unsigned& failurePosition, String& reportURL);
Modified: trunk/Source/WebCore/platform/network/MIMEHeader.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/MIMEHeader.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/MIMEHeader.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -72,7 +72,7 @@
// This is not a key value pair, ignore.
continue;
}
- key = StringView(line).left(semicolonIndex).convertToASCIILowercase().stripWhiteSpace();
+ key = StringView(line).left(semicolonIndex).stripWhiteSpace().convertToASCIILowercase();
value.append(StringView(line).substring(semicolonIndex + 1));
}
// Store the last property if there is one.
@@ -120,9 +120,9 @@
return mimeHeader;
}
-MIMEHeader::Encoding MIMEHeader::parseContentTransferEncoding(const String& text)
+MIMEHeader::Encoding MIMEHeader::parseContentTransferEncoding(StringView text)
{
- String encoding = text.stripWhiteSpace();
+ auto encoding = text.stripWhiteSpace();
if (equalLettersIgnoringASCIICase(encoding, "base64"))
return Base64;
if (equalLettersIgnoringASCIICase(encoding, "quoted-printable"))
Modified: trunk/Source/WebCore/platform/network/MIMEHeader.h (292950 => 292951)
--- trunk/Source/WebCore/platform/network/MIMEHeader.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/MIMEHeader.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -68,7 +68,7 @@
private:
MIMEHeader();
- static Encoding parseContentTransferEncoding(const String&);
+ static Encoding parseContentTransferEncoding(StringView);
String m_contentType;
String m_charset;
Modified: trunk/Source/WebCore/platform/network/ParsedContentType.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/ParsedContentType.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/ParsedContentType.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -369,7 +369,7 @@
{
m_mimeType = WTFMove(contentRange);
if (mode == Mode::MimeSniff)
- m_mimeType = stripLeadingAndTrailingHTTPSpaces(m_mimeType).convertToASCIILowercase();
+ m_mimeType = stripLeadingAndTrailingHTTPSpaces(StringView(m_mimeType)).convertToASCIILowercase();
else
m_mimeType = m_mimeType.stripWhiteSpace();
}
Modified: trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -781,7 +781,7 @@
lazyInit(AllFields);
auto value = m_httpHeaderFields.get(HTTPHeaderName::ContentDisposition);
- return equalLettersIgnoringASCIICase(value.left(value.find(';')).stripWhiteSpace(), "attachment");
+ return equalLettersIgnoringASCIICase(StringView(value).left(value.find(';')).stripWhiteSpace(), "attachment");
}
bool ResourceResponseBase::isAttachmentWithFilename() const
@@ -796,8 +796,7 @@
if (!equalLettersIgnoringASCIICase(contentDispositionView.left(contentDispositionView.find(';')).stripWhiteSpace(), "attachment"))
return false;
- String filename = filenameFromHTTPContentDisposition(contentDispositionView);
- return !filename.isNull();
+ return !filenameFromHTTPContentDisposition(contentDispositionView).isNull();
}
ResourceResponseBase::Source ResourceResponseBase::source() const
Modified: trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -151,7 +151,7 @@
String ResourceResponse::platformSuggestedFilename() const
{
- return filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition));
+ return filenameFromHTTPContentDisposition(httpHeaderField(HTTPHeaderName::ContentDisposition)).toString();
}
bool ResourceResponse::shouldRedirect()
Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp (292950 => 292951)
--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -409,7 +409,7 @@
LOG(SQLDatabase, "Busy handler set on non-open database");
}
-bool SQLiteDatabase::executeCommandSlow(const String& query)
+bool SQLiteDatabase::executeCommandSlow(StringView query)
{
auto statement = prepareStatementSlow(query);
return statement && statement->executeCommand();
@@ -461,7 +461,7 @@
while (statement->step() == SQLITE_ROW)
tables.append(statement->columnText(0));
for (auto& table : tables) {
- if (!executeCommandSlow("DROP TABLE " + table))
+ if (!executeCommandSlow(makeString("DROP TABLE ", table)))
LOG(SQLDatabase, "Unable to drop table %s", table.ascii().data());
}
}
@@ -723,7 +723,7 @@
return statement;
}
-Expected<SQLiteStatement, int> SQLiteDatabase::prepareStatementSlow(const String& queryString)
+Expected<SQLiteStatement, int> SQLiteDatabase::prepareStatementSlow(StringView queryString)
{
CString query = queryString.stripWhiteSpace().utf8();
auto sqlStatement = constructAndPrepareStatement(*this, query.data(), query.length());
@@ -744,7 +744,7 @@
return SQLiteStatement { *this, sqlStatement.value() };
}
-Expected<UniqueRef<SQLiteStatement>, int> SQLiteDatabase::prepareHeapStatementSlow(const String& queryString)
+Expected<UniqueRef<SQLiteStatement>, int> SQLiteDatabase::prepareHeapStatementSlow(StringView queryString)
{
CString query = queryString.stripWhiteSpace().utf8();
auto sqlStatement = constructAndPrepareStatement(*this, query.data(), query.length());
Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.h (292950 => 292951)
--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -63,7 +63,7 @@
bool isOpen() const { return m_db; }
WEBCORE_EXPORT void close();
- WEBCORE_EXPORT bool executeCommandSlow(const String&);
+ WEBCORE_EXPORT bool executeCommandSlow(StringView);
WEBCORE_EXPORT bool executeCommand(ASCIILiteral);
WEBCORE_EXPORT bool tableExists(StringView);
@@ -75,9 +75,9 @@
bool transactionInProgress() const { return m_transactionInProgress; }
- WEBCORE_EXPORT Expected<SQLiteStatement, int> prepareStatementSlow(const String& query);
+ WEBCORE_EXPORT Expected<SQLiteStatement, int> prepareStatementSlow(StringView query);
WEBCORE_EXPORT Expected<SQLiteStatement, int> prepareStatement(ASCIILiteral query);
- WEBCORE_EXPORT Expected<UniqueRef<SQLiteStatement>, int> prepareHeapStatementSlow(const String& query);
+ WEBCORE_EXPORT Expected<UniqueRef<SQLiteStatement>, int> prepareHeapStatementSlow(StringView query);
WEBCORE_EXPORT Expected<UniqueRef<SQLiteStatement>, int> prepareHeapStatement(ASCIILiteral query);
// Aborts the current database operation. This is thread safe.
Modified: trunk/Source/WebCore/platform/xr/PlatformXR.h (292950 => 292951)
--- trunk/Source/WebCore/platform/xr/PlatformXR.h 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/platform/xr/PlatformXR.h 2022-04-18 05:55:56 UTC (rev 292951)
@@ -115,9 +115,9 @@
return SessionFeature::ReferenceSpaceTypeViewer;
}
-inline std::optional<SessionFeature> parseSessionFeatureDescriptor(const String& string)
+inline std::optional<SessionFeature> parseSessionFeatureDescriptor(StringView string)
{
- String feature = string.stripWhiteSpace().convertToASCIILowercase();
+ auto feature = string.stripWhiteSpace().convertToASCIILowercase();
if (feature == "viewer"_s)
return SessionFeature::ReferenceSpaceTypeViewer;
Modified: trunk/Source/WebCore/svg/SVGAnimationElement.cpp (292950 => 292951)
--- trunk/Source/WebCore/svg/SVGAnimationElement.cpp 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebCore/svg/SVGAnimationElement.cpp 2022-04-18 05:55:56 UTC (rev 292951)
@@ -56,11 +56,11 @@
{
}
-static void parseKeyTimes(const String& parse, Vector<float>& result, bool verifyOrder)
+static void parseKeyTimes(StringView parse, Vector<float>& result, bool verifyOrder)
{
result.clear();
bool isFirst = true;
- for (StringView timeString : StringView(parse).split(';')) {
+ for (auto timeString : parse.split(';')) {
bool ok;
float time = timeString.toFloat(ok);
if (!ok || time < 0 || time > 1)
@@ -153,9 +153,10 @@
// Per the SMIL specification, leading and trailing white space,
// and white space before and after semicolon separators, is allowed and will be ignored.
// http://www.w3.org/TR/SVG11/animate.html#ValuesAttribute
- m_values = value.string().split(';');
- for (auto& value : m_values)
- value = value.stripWhiteSpace();
+ m_values.clear();
+ value.string().split(';', [this](StringView innerValue) {
+ m_values.append(innerValue.stripWhiteSpace().toString());
+ });
updateAnimationMode();
return;
Modified: trunk/Source/WebKit/ChangeLog (292950 => 292951)
--- trunk/Source/WebKit/ChangeLog 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebKit/ChangeLog 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1,3 +1,15 @@
+2022-04-17 Chris Dumez <cdu...@apple.com>
+
+ Leverage StringView in more places
+ https://bugs.webkit.org/show_bug.cgi?id=239426
+
+ Reviewed by Sam Weinig.
+
+ Leverage StringView in more places, to reduce the number of String allocations.
+
+ * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+ (WebKit::WebPage::dictionaryPopupInfoForRange):
+
2022-04-16 Chris Dumez <cdu...@apple.com>
Drop String::truncate() and use String::left() instead
Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (292950 => 292951)
--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm 2022-04-18 05:55:56 UTC (rev 292951)
@@ -164,8 +164,7 @@
Editor& editor = frame.editor();
editor.setIsGettingDictionaryPopupInfo(true);
- // FIXME: Inefficient to call stripWhiteSpace to detect whether a string has a non-whitespace character in it.
- if (plainText(range).stripWhiteSpace().isEmpty()) {
+ if (plainText(range).find(isNotSpaceOrNewline) == notFound) {
editor.setIsGettingDictionaryPopupInfo(false);
return { };
}
Modified: trunk/Source/WebKitLegacy/mac/ChangeLog (292950 => 292951)
--- trunk/Source/WebKitLegacy/mac/ChangeLog 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebKitLegacy/mac/ChangeLog 2022-04-18 05:55:56 UTC (rev 292951)
@@ -1,3 +1,15 @@
+2022-04-17 Chris Dumez <cdu...@apple.com>
+
+ Leverage StringView in more places
+ https://bugs.webkit.org/show_bug.cgi?id=239426
+
+ Reviewed by Sam Weinig.
+
+ Leverage StringView in more places, to reduce the number of String allocations.
+
+ * WebView/WebImmediateActionController.mm:
+ (+[WebImmediateActionController _dictionaryPopupInfoForRange:inFrame:withLookupOptions:indicatorOptions:transition:]):
+
2022-04-15 Chris Dumez <cdu...@apple.com>
Leverage StringView in more places to avoid some String allocations
Modified: trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm (292950 => 292951)
--- trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm 2022-04-17 21:52:53 UTC (rev 292950)
+++ trunk/Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm 2022-04-18 05:55:56 UTC (rev 292951)
@@ -517,7 +517,7 @@
// Dictionary API will accept a whitespace-only string and display UI as if it were real text,
// so bail out early to avoid that.
WebCore::DictionaryPopupInfo popupInfo;
- if (plainText(range).stripWhiteSpace().isEmpty()) {
+ if (plainText(range).find(isNotSpaceOrNewline) == notFound) {
editor.setIsGettingDictionaryPopupInfo(false);
return popupInfo;
}