- Revision
- 248316
- Author
- [email protected]
- Date
- 2019-08-06 14:45:32 -0700 (Tue, 06 Aug 2019)
Log Message
Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
https://bugs.webkit.org/show_bug.cgi?id=200475
Reviewed by Darin Adler.
Source/WebCore:
In the case where CFStringGetCStringPtr() succeeds in returning us a pointer
to the CFStringRef underlying characters but it is not a common header, we
would fall back to calling HTTPHeaderMap::set(const String&, const String&)
which would unecessarily call findHTTPHeaderName() again to try and determine
if it is a common header. Avoid this by introducing a new setUncommonHeader()
private method and calling this one instead. Also got rid of some code
duplication at the same time.
* platform/network/HTTPHeaderMap.cpp:
(WebCore::HTTPHeaderMap::set):
(WebCore::HTTPHeaderMap::setUncommonHeader):
* platform/network/HTTPHeaderMap.h:
* platform/network/HTTPParsers.cpp:
(WebCore::parseHTTPHeader):
* testing/MockCDMFactory.cpp:
(WebCore::MockCDMInstance::setServerCertificate):
Source/WTF:
Add convenience constuctor to StringView which takes in a const char*
and an unsigned length, similarly to what we already have for String.
* wtf/URL.cpp:
(WTF::URL::protocolIs const):
(WTF::protocolIsInternal):
* wtf/text/StringView.h:
(WTF::StringView::StringView):
(WTF::StringView::empty):
Tools:
* TestWebKitAPI/Tests/WTF/StringView.cpp:
(TestWebKitAPI::stringViewFromLiteral):
(TestWebKitAPI::stringViewFromUTF8):
Modified Paths
Diff
Modified: trunk/Source/WTF/ChangeLog (248315 => 248316)
--- trunk/Source/WTF/ChangeLog 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WTF/ChangeLog 2019-08-06 21:45:32 UTC (rev 248316)
@@ -1,3 +1,20 @@
+2019-08-06 Chris Dumez <[email protected]>
+
+ Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
+ https://bugs.webkit.org/show_bug.cgi?id=200475
+
+ Reviewed by Darin Adler.
+
+ Add convenience constuctor to StringView which takes in a const char*
+ and an unsigned length, similarly to what we already have for String.
+
+ * wtf/URL.cpp:
+ (WTF::URL::protocolIs const):
+ (WTF::protocolIsInternal):
+ * wtf/text/StringView.h:
+ (WTF::StringView::StringView):
+ (WTF::StringView::empty):
+
2019-08-06 Jiewen Tan <[email protected]>
[WebAuthN] Enable LocalAuthenticator for macOS
Modified: trunk/Source/WTF/wtf/URL.cpp (248315 => 248316)
--- trunk/Source/WTF/wtf/URL.cpp 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WTF/wtf/URL.cpp 2019-08-06 21:45:32 UTC (rev 248316)
@@ -314,7 +314,7 @@
bool URL::protocolIs(const char* protocol) const
{
- assertProtocolIsGood(StringView(reinterpret_cast<const LChar*>(protocol), strlen(protocol)));
+ assertProtocolIsGood(StringView { protocol });
// _javascript_ URLs are "valid" and should be executed even if URL decides they are invalid.
// The free function protocolIsJavaScript() should be used instead.
@@ -770,7 +770,7 @@
bool protocolIsInternal(const StringClass& url, const char* protocol)
{
// Do the comparison without making a new string object.
- assertProtocolIsGood(StringView(reinterpret_cast<const LChar*>(protocol), strlen(protocol)));
+ assertProtocolIsGood(StringView { protocol });
bool isLeading = true;
for (unsigned i = 0, j = 0; url[i]; ++i) {
// Skip leading whitespace and control characters.
Modified: trunk/Source/WTF/wtf/text/StringView.h (248315 => 248316)
--- trunk/Source/WTF/wtf/text/StringView.h 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WTF/wtf/text/StringView.h 2019-08-06 21:45:32 UTC (rev 248316)
@@ -66,6 +66,7 @@
StringView(const LChar*, unsigned length);
StringView(const UChar*, unsigned length);
StringView(const char*);
+ StringView(const char*, unsigned length);
static StringView empty();
@@ -329,6 +330,11 @@
initialize(reinterpret_cast<const LChar*>(characters), strlen(characters));
}
+inline StringView::StringView(const char* characters, unsigned length)
+{
+ initialize(reinterpret_cast<const LChar*>(characters), length);
+}
+
inline StringView::StringView(const StringImpl& string)
{
setUnderlyingString(&string);
@@ -378,7 +384,7 @@
inline StringView StringView::empty()
{
- return StringView(reinterpret_cast<const LChar*>(""), 0);
+ return StringView("", 0);
}
inline const LChar* StringView::characters8() const
Modified: trunk/Source/WebCore/ChangeLog (248315 => 248316)
--- trunk/Source/WebCore/ChangeLog 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WebCore/ChangeLog 2019-08-06 21:45:32 UTC (rev 248316)
@@ -1,3 +1,27 @@
+2019-08-06 Chris Dumez <[email protected]>
+
+ Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
+ https://bugs.webkit.org/show_bug.cgi?id=200475
+
+ Reviewed by Darin Adler.
+
+ In the case where CFStringGetCStringPtr() succeeds in returning us a pointer
+ to the CFStringRef underlying characters but it is not a common header, we
+ would fall back to calling HTTPHeaderMap::set(const String&, const String&)
+ which would unecessarily call findHTTPHeaderName() again to try and determine
+ if it is a common header. Avoid this by introducing a new setUncommonHeader()
+ private method and calling this one instead. Also got rid of some code
+ duplication at the same time.
+
+ * platform/network/HTTPHeaderMap.cpp:
+ (WebCore::HTTPHeaderMap::set):
+ (WebCore::HTTPHeaderMap::setUncommonHeader):
+ * platform/network/HTTPHeaderMap.h:
+ * platform/network/HTTPParsers.cpp:
+ (WebCore::parseHTTPHeader):
+ * testing/MockCDMFactory.cpp:
+ (WebCore::MockCDMInstance::setServerCertificate):
+
2019-08-06 Saam Barati <[email protected]>
[WHLSL] Remove the auto initialize variables pass
Modified: trunk/Source/WebCore/platform/network/HTTPHeaderMap.cpp (248315 => 248316)
--- trunk/Source/WebCore/platform/network/HTTPHeaderMap.cpp 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderMap.cpp 2019-08-06 21:45:32 UTC (rev 248316)
@@ -69,16 +69,11 @@
if (auto* nameCharacters = CFStringGetCStringPtr(name, kCFStringEncodingASCII)) {
unsigned length = CFStringGetLength(name);
HTTPHeaderName headerName;
- if (findHTTPHeaderName(StringView(reinterpret_cast<const LChar*>(nameCharacters), length), headerName)) {
- auto index = m_commonHeaders.findMatching([&](auto& header) {
- return header.key == headerName;
- });
- if (index == notFound)
- m_commonHeaders.append(CommonHeader { headerName, value });
- else
- m_commonHeaders[index].value = value;
- } else
- set(String(nameCharacters, length), value);
+ if (findHTTPHeaderName(StringView(nameCharacters, length), headerName))
+ set(headerName, value);
+ else
+ setUncommonHeader(String(nameCharacters, length), value);
+
return;
}
@@ -95,6 +90,11 @@
return;
}
+ setUncommonHeader(name, value);
+}
+
+void HTTPHeaderMap::setUncommonHeader(const String& name, const String& value)
+{
auto index = m_uncommonHeaders.findMatching([&](auto& header) {
return equalIgnoringASCIICase(header.key, name);
});
Modified: trunk/Source/WebCore/platform/network/HTTPHeaderMap.h (248315 => 248316)
--- trunk/Source/WebCore/platform/network/HTTPHeaderMap.h 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WebCore/platform/network/HTTPHeaderMap.h 2019-08-06 21:45:32 UTC (rev 248316)
@@ -202,6 +202,8 @@
template <class Decoder> static bool decode(Decoder&, HTTPHeaderMap&);
private:
+ void setUncommonHeader(const String& name, const String& value);
+
CommonHeadersVector m_commonHeaders;
UncommonHeadersVector m_uncommonHeaders;
};
Modified: trunk/Source/WebCore/platform/network/HTTPParsers.cpp (248315 => 248316)
--- trunk/Source/WebCore/platform/network/HTTPParsers.cpp 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WebCore/platform/network/HTTPParsers.cpp 2019-08-06 21:45:32 UTC (rev 248316)
@@ -728,7 +728,7 @@
}
nameSize = name.size();
- nameStr = StringView(reinterpret_cast<const LChar*>(namePtr), nameSize);
+ nameStr = StringView(namePtr, nameSize);
for (; p < end && *p == 0x20; p++) { }
Modified: trunk/Source/WebCore/testing/MockCDMFactory.cpp (248315 => 248316)
--- trunk/Source/WebCore/testing/MockCDMFactory.cpp 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Source/WebCore/testing/MockCDMFactory.cpp 2019-08-06 21:45:32 UTC (rev 248316)
@@ -269,7 +269,7 @@
CDMInstance::SuccessValue MockCDMInstance::setServerCertificate(Ref<SharedBuffer>&& certificate)
{
- StringView certificateStringView(reinterpret_cast<const LChar*>(certificate->data()), certificate->size());
+ StringView certificateStringView(certificate->data(), certificate->size());
if (equalIgnoringASCIICase(certificateStringView, "valid"))
return Succeeded;
Modified: trunk/Tools/ChangeLog (248315 => 248316)
--- trunk/Tools/ChangeLog 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Tools/ChangeLog 2019-08-06 21:45:32 UTC (rev 248316)
@@ -1,3 +1,14 @@
+2019-08-06 Chris Dumez <[email protected]>
+
+ Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
+ https://bugs.webkit.org/show_bug.cgi?id=200475
+
+ Reviewed by Darin Adler.
+
+ * TestWebKitAPI/Tests/WTF/StringView.cpp:
+ (TestWebKitAPI::stringViewFromLiteral):
+ (TestWebKitAPI::stringViewFromUTF8):
+
2019-08-06 Carlos Alberto Lopez Perez <[email protected]>
Update my status in contributors.json to reviewer.
Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp (248315 => 248316)
--- trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp 2019-08-06 21:34:08 UTC (rev 248315)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp 2019-08-06 21:45:32 UTC (rev 248316)
@@ -32,10 +32,10 @@
StringView stringViewFromLiteral(const char* characters)
{
- return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
+ return StringView(characters);
}
-StringView stringViewFromUTF8(String &ref, const char* characters)
+StringView stringViewFromUTF8(String& ref, const char* characters)
{
ref = String::fromUTF8(characters);
return ref;