⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 248316 in webkit


Ignore:
Timestamp:
Aug 6, 2019, 2:45:32 PM (7 years ago)
Author:
Chris Dumez
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):

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r248308 r248316  
     12019-08-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
     4        https://bugs.webkit.org/show_bug.cgi?id=200475
     5
     6        Reviewed by Darin Adler.
     7
     8        Add convenience constuctor to StringView which takes in a const char*
     9        and an unsigned length, similarly to what we already have for String.
     10
     11        * wtf/URL.cpp:
     12        (WTF::URL::protocolIs const):
     13        (WTF::protocolIsInternal):
     14        * wtf/text/StringView.h:
     15        (WTF::StringView::StringView):
     16        (WTF::StringView::empty):
     17
    1182019-08-06  Jiewen Tan  <jiewen_tan@apple.com>
    219
  • trunk/Source/WTF/wtf/URL.cpp

    r243118 r248316  
    315315bool URL::protocolIs(const char* protocol) const
    316316{
    317     assertProtocolIsGood(StringView(reinterpret_cast<const LChar*>(protocol), strlen(protocol)));
     317    assertProtocolIsGood(StringView { protocol });
    318318
    319319    // JavaScript URLs are "valid" and should be executed even if URL decides they are invalid.
     
    771771{
    772772    // Do the comparison without making a new string object.
    773     assertProtocolIsGood(StringView(reinterpret_cast<const LChar*>(protocol), strlen(protocol)));
     773    assertProtocolIsGood(StringView { protocol });
    774774    bool isLeading = true;
    775775    for (unsigned i = 0, j = 0; url[i]; ++i) {
  • trunk/Source/WTF/wtf/text/StringView.h

    r246951 r248316  
    6767    StringView(const UChar*, unsigned length);
    6868    StringView(const char*);
     69    StringView(const char*, unsigned length);
    6970
    7071    static StringView empty();
     
    330331}
    331332
     333inline StringView::StringView(const char* characters, unsigned length)
     334{
     335    initialize(reinterpret_cast<const LChar*>(characters), length);
     336}
     337
    332338inline StringView::StringView(const StringImpl& string)
    333339{
     
    379385inline StringView StringView::empty()
    380386{
    381     return StringView(reinterpret_cast<const LChar*>(""), 0);
     387    return StringView("", 0);
    382388}
    383389
  • trunk/Source/WebCore/ChangeLog

    r248310 r248316  
     12019-08-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
     4        https://bugs.webkit.org/show_bug.cgi?id=200475
     5
     6        Reviewed by Darin Adler.
     7
     8        In the case where CFStringGetCStringPtr() succeeds in returning us a pointer
     9        to the CFStringRef underlying characters but it is not a common header, we
     10        would fall back to calling HTTPHeaderMap::set(const String&, const String&)
     11        which would unecessarily call findHTTPHeaderName() again to try and determine
     12        if it is a common header. Avoid this by introducing a new setUncommonHeader()
     13        private method and calling this one instead. Also got rid of some code
     14        duplication at the same time.
     15
     16        * platform/network/HTTPHeaderMap.cpp:
     17        (WebCore::HTTPHeaderMap::set):
     18        (WebCore::HTTPHeaderMap::setUncommonHeader):
     19        * platform/network/HTTPHeaderMap.h:
     20        * platform/network/HTTPParsers.cpp:
     21        (WebCore::parseHTTPHeader):
     22        * testing/MockCDMFactory.cpp:
     23        (WebCore::MockCDMInstance::setServerCertificate):
     24
    1252019-08-06  Saam Barati  <sbarati@apple.com>
    226
  • trunk/Source/WebCore/platform/network/HTTPHeaderMap.cpp

    r232964 r248316  
    7070        unsigned length = CFStringGetLength(name);
    7171        HTTPHeaderName headerName;
    72         if (findHTTPHeaderName(StringView(reinterpret_cast<const LChar*>(nameCharacters), length), headerName)) {
    73             auto index = m_commonHeaders.findMatching([&](auto& header) {
    74                 return header.key == headerName;
    75             });
    76             if (index == notFound)
    77                 m_commonHeaders.append(CommonHeader { headerName, value });
    78             else
    79                 m_commonHeaders[index].value = value;
    80         } else
    81             set(String(nameCharacters, length), value);
     72        if (findHTTPHeaderName(StringView(nameCharacters, length), headerName))
     73            set(headerName, value);
     74        else
     75            setUncommonHeader(String(nameCharacters, length), value);
     76
    8277        return;
    8378    }
     
    9691    }
    9792
     93    setUncommonHeader(name, value);
     94}
     95
     96void HTTPHeaderMap::setUncommonHeader(const String& name, const String& value)
     97{
    9898    auto index = m_uncommonHeaders.findMatching([&](auto& header) {
    9999        return equalIgnoringASCIICase(header.key, name);
  • trunk/Source/WebCore/platform/network/HTTPHeaderMap.h

    r239427 r248316  
    203203
    204204private:
     205    void setUncommonHeader(const String& name, const String& value);
     206
    205207    CommonHeadersVector m_commonHeaders;
    206208    UncommonHeadersVector m_uncommonHeaders;
  • trunk/Source/WebCore/platform/network/HTTPParsers.cpp

    r246490 r248316  
    729729
    730730    nameSize = name.size();
    731     nameStr = StringView(reinterpret_cast<const LChar*>(namePtr), nameSize);
     731    nameStr = StringView(namePtr, nameSize);
    732732
    733733    for (; p < end && *p == 0x20; p++) { }
  • trunk/Source/WebCore/testing/MockCDMFactory.cpp

    r246490 r248316  
    270270CDMInstance::SuccessValue MockCDMInstance::setServerCertificate(Ref<SharedBuffer>&& certificate)
    271271{
    272     StringView certificateStringView(reinterpret_cast<const LChar*>(certificate->data()), certificate->size());
     272    StringView certificateStringView(certificate->data(), certificate->size());
    273273
    274274    if (equalIgnoringASCIICase(certificateStringView, "valid"))
  • trunk/Tools/ChangeLog

    r248315 r248316  
     12019-08-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Fix inefficiency in HTTPHeaderMap::set(CFStringRef, const String&)
     4        https://bugs.webkit.org/show_bug.cgi?id=200475
     5
     6        Reviewed by Darin Adler.
     7
     8        * TestWebKitAPI/Tests/WTF/StringView.cpp:
     9        (TestWebKitAPI::stringViewFromLiteral):
     10        (TestWebKitAPI::stringViewFromUTF8):
     11
    1122019-08-06  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

    r234278 r248316  
    3333StringView stringViewFromLiteral(const char* characters)
    3434{
    35     return StringView(reinterpret_cast<const LChar*>(characters), strlen(characters));
    36 }
    37 
    38 StringView stringViewFromUTF8(String &ref, const char* characters)
     35    return StringView(characters);
     36}
     37
     38StringView stringViewFromUTF8(String& ref, const char* characters)
    3939{
    4040    ref = String::fromUTF8(characters);
Note: See TracChangeset for help on using the changeset viewer.