Diff
Modified: trunk/Source/WTF/ChangeLog (274186 => 274187)
--- trunk/Source/WTF/ChangeLog 2021-03-10 00:40:08 UTC (rev 274186)
+++ trunk/Source/WTF/ChangeLog 2021-03-10 00:43:27 UTC (rev 274187)
@@ -1,3 +1,14 @@
+2021-03-09 Alex Christensen <achristen...@webkit.org>
+
+ Reduce unnecessary string copies in ParsedContentRange
+ https://bugs.webkit.org/show_bug.cgi?id=221769
+
+ Reviewed by Geoff Garen.
+
+ * wtf/text/StringView.h:
+ (WTF::StringView::toInt64Strict const):
+ * wtf/text/WTFString.h:
+
2021-03-09 Commit Queue <commit-qu...@webkit.org>
Unreviewed, reverting r274171.
Modified: trunk/Source/WTF/wtf/text/StringView.h (274186 => 274187)
--- trunk/Source/WTF/wtf/text/StringView.h 2021-03-10 00:40:08 UTC (rev 274186)
+++ trunk/Source/WTF/wtf/text/StringView.h 2021-03-10 00:43:27 UTC (rev 274187)
@@ -172,6 +172,7 @@
int toInt(bool& isValid) const;
int toIntStrict(bool& isValid) const;
Optional<uint64_t> toUInt64Strict() const;
+ Optional<int64_t> toInt64Strict() const;
float toFloat(bool& isValid) const;
static void invalidate(const StringImpl&);
@@ -614,6 +615,13 @@
return isValid ? makeOptional(result) : WTF::nullopt;
}
+inline Optional<int64_t> StringView::toInt64Strict() const
+{
+ bool isValid;
+ int64_t result = is8Bit() ? charactersToInt64Strict(characters8(), m_length, &isValid) : charactersToInt64Strict(characters16(), m_length, &isValid);
+ return isValid ? makeOptional(result) : WTF::nullopt;
+}
+
inline String StringView::toStringWithoutCopying() const
{
if (is8Bit())
Modified: trunk/Source/WTF/wtf/text/WTFString.h (274186 => 274187)
--- trunk/Source/WTF/wtf/text/WTFString.h 2021-03-10 00:40:08 UTC (rev 274186)
+++ trunk/Source/WTF/wtf/text/WTFString.h 2021-03-10 00:43:27 UTC (rev 274187)
@@ -46,8 +46,8 @@
WTF_EXPORT_PRIVATE int charactersToIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
WTF_EXPORT_PRIVATE unsigned charactersToUIntStrict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
-int64_t charactersToInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
-int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
+WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
+WTF_EXPORT_PRIVATE int64_t charactersToInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
WTF_EXPORT_PRIVATE uint64_t charactersToUInt64Strict(const UChar*, size_t, bool* ok = nullptr, int base = 10);
intptr_t charactersToIntPtrStrict(const LChar*, size_t, bool* ok = nullptr, int base = 10);
Modified: trunk/Source/WebCore/ChangeLog (274186 => 274187)
--- trunk/Source/WebCore/ChangeLog 2021-03-10 00:40:08 UTC (rev 274186)
+++ trunk/Source/WebCore/ChangeLog 2021-03-10 00:43:27 UTC (rev 274187)
@@ -1,3 +1,18 @@
+2021-03-09 Alex Christensen <achristen...@webkit.org>
+
+ Reduce unnecessary string copies in ParsedContentRange
+ https://bugs.webkit.org/show_bug.cgi?id=221769
+
+ Reviewed by Geoff Garen.
+
+ * platform/network/ParsedContentRange.cpp:
+ (WebCore::parseContentRange):
+ (WebCore::ParsedContentRange::ParsedContentRange):
+ * platform/network/ParsedRequestRange.cpp:
+ (WebCore::ParsedRequestRange::parse):
+ * platform/network/ParsedRequestRange.h:
+ (WebCore::ParsedRequestRange::parse):
+
2021-03-09 Ben Nham <n...@apple.com>
REGRESSION: [BigSur] ASSERT NOT REACHED in WebCore::ResourceLoadPriority WebCore::toResourceLoadPriority
Modified: trunk/Source/WebCore/platform/network/ParsedContentRange.cpp (274186 => 274187)
--- trunk/Source/WebCore/platform/network/ParsedContentRange.cpp 2021-03-10 00:40:08 UTC (rev 274186)
+++ trunk/Source/WebCore/platform/network/ParsedContentRange.cpp 2021-03-10 00:43:27 UTC (rev 274187)
@@ -51,7 +51,7 @@
return lastBytePosition < instanceLength;
}
-static bool parseContentRange(const String& headerValue, int64_t& firstBytePosition, int64_t& lastBytePosition, int64_t& instanceLength)
+static bool parseContentRange(StringView headerValue, int64_t& firstBytePosition, int64_t& lastBytePosition, int64_t& instanceLength)
{
// From <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>
// 14.16 Content-Range
@@ -79,24 +79,25 @@
if (instanceLengthSeparatorToken == notFound)
return false;
- bool isOk = true;
- String firstByteString = headerValue.substring(prefixLength, byteSeparatorTokenLoc - prefixLength);
+ auto firstByteString = headerValue.substring(prefixLength, byteSeparatorTokenLoc - prefixLength);
if (!firstByteString.isAllSpecialCharacters<isASCIIDigit>())
return false;
- firstBytePosition = firstByteString.toInt64Strict(&isOk);
- if (!isOk)
+ auto optionalFirstBytePosition = firstByteString.toInt64Strict();
+ if (!optionalFirstBytePosition)
return false;
+ firstBytePosition = *optionalFirstBytePosition;
- String lastByteString = headerValue.substring(byteSeparatorTokenLoc + 1, instanceLengthSeparatorToken - (byteSeparatorTokenLoc + 1));
+ auto lastByteString = headerValue.substring(byteSeparatorTokenLoc + 1, instanceLengthSeparatorToken - (byteSeparatorTokenLoc + 1));
if (!lastByteString.isAllSpecialCharacters<isASCIIDigit>())
return false;
- lastBytePosition = lastByteString.toInt64Strict(&isOk);
- if (!isOk)
+ auto optionalLastBytePosition = lastByteString.toInt64Strict();
+ if (!optionalLastBytePosition)
return false;
+ lastBytePosition = *optionalLastBytePosition;
- String instanceString = headerValue.substring(instanceLengthSeparatorToken + 1);
+ auto instanceString = headerValue.substring(instanceLengthSeparatorToken + 1);
if (instanceString == "*")
instanceLength = ParsedContentRange::unknownLength;
else {
@@ -103,9 +104,10 @@
if (!instanceString.isAllSpecialCharacters<isASCIIDigit>())
return false;
- instanceLength = instanceString.toInt64Strict(&isOk);
- if (!isOk)
+ auto optionalInstanceLength = instanceString.toInt64Strict();
+ if (!optionalInstanceLength)
return false;
+ instanceLength = *optionalInstanceLength;
}
return areContentRangeValuesValid(firstBytePosition, lastBytePosition, instanceLength);
@@ -113,7 +115,7 @@
ParsedContentRange::ParsedContentRange(const String& headerValue)
{
- if (!parseContentRange(headerValue, m_firstBytePosition, m_lastBytePosition, m_instanceLength))
+ if (!parseContentRange(StringView(headerValue), m_firstBytePosition, m_lastBytePosition, m_instanceLength))
m_instanceLength = invalidLength;
}