Changeset 206076 in webkit


Ignore:
Timestamp:
Sep 18, 2016 1:01:11 AM (8 years ago)
Author:
achristensen@apple.com
Message:

Remove unnecessary String allocations in URLParser
https://bugs.webkit.org/show_bug.cgi?id=162089

Reviewed by Chris Dumez.

No change in behavior except a performance improvement.

  • platform/URL.cpp:

(WebCore::assertProtocolIsGood):
(WebCore::URL::protocolIs):
(WebCore::protocolIs):

  • platform/URL.h:

Added a new protocolIs for non-null-terminated strings from user input.

  • platform/URLParser.cpp:

(WebCore::URLParser::parse):
Don't make a String to compare protocols.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r206075 r206076  
     12016-09-18  Alex Christensen  <achristensen@webkit.org>
     2
     3        Remove unnecessary String allocations in URLParser
     4        https://bugs.webkit.org/show_bug.cgi?id=162089
     5
     6        Reviewed by Chris Dumez.
     7
     8        No change in behavior except a performance improvement.
     9
     10        * platform/URL.cpp:
     11        (WebCore::assertProtocolIsGood):
     12        (WebCore::URL::protocolIs):
     13        (WebCore::protocolIs):
     14        * platform/URL.h:
     15        Added a new protocolIs for non-null-terminated strings from user input.
     16        * platform/URLParser.cpp:
     17        (WebCore::URLParser::parse):
     18        Don't make a String to compare protocols.
     19
    1202016-09-17  Alex Christensen  <achristensen@webkit.org>
    221
  • trunk/Source/WebCore/platform/URL.cpp

    r205782 r206076  
    791791#ifdef NDEBUG
    792792
    793 static inline void assertProtocolIsGood(const char*)
     793static inline void assertProtocolIsGood(const char*, size_t)
    794794{
    795795}
     
    797797#else
    798798
    799 static void assertProtocolIsGood(const char* protocol)
    800 {
    801     const char* p = protocol;
    802     while (*p) {
    803         ASSERT(*p > ' ' && *p < 0x7F && !(*p >= 'A' && *p <= 'Z'));
    804         ++p;
     799static void assertProtocolIsGood(const char* protocol, size_t length)
     800{
     801    for (size_t i = 0; i < length; ++i) {
     802        const char c = protocol[i];
     803        ASSERT(c > ' ' && c < 0x7F && !(c >= 'A' && c <= 'Z'));
    805804    }
    806805}
     
    810809bool URL::protocolIs(const char* protocol) const
    811810{
    812     assertProtocolIsGood(protocol);
     811    assertProtocolIsGood(protocol, strlen(protocol));
    813812
    814813    // JavaScript URLs are "valid" and should be executed even if URL decides they are invalid.
     
    825824    }
    826825    return !protocol[m_schemeEnd]; // We should have consumed all characters in the argument.
     826}
     827
     828bool URL::protocolIs(const LChar* protocol, size_t length) const
     829{
     830    assertProtocolIsGood(reinterpret_cast<const char*>(protocol), length);
     831
     832    if (!m_isValid)
     833        return false;
     834   
     835    if (m_schemeEnd != length)
     836        return false;
     837
     838    // Do the comparison without making a new string object.
     839    for (unsigned i = 0; i < m_schemeEnd; ++i) {
     840        if (!isSchemeCharacterMatchIgnoringCase(m_string[i], protocol[i]))
     841            return false;
     842    }
     843    return true;
    827844}
    828845
     
    19001917static bool protocolIs(StringView stringURL, const char* protocol)
    19011918{
    1902     assertProtocolIsGood(protocol);
     1919    assertProtocolIsGood(protocol, strlen(protocol));
    19031920    unsigned length = stringURL.length();
    19041921    for (unsigned i = 0; i < length; ++i) {
     
    21232140}
    21242141
     2142// FIXME: Why is this different than protocolIs(StringView, const char*)?
    21252143bool protocolIs(const String& url, const char* protocol)
    21262144{
    21272145    // Do the comparison without making a new string object.
    2128     assertProtocolIsGood(protocol);
     2146    assertProtocolIsGood(protocol, strlen(protocol));
    21292147    bool isLeading = true;
    21302148    for (unsigned i = 0, j = 0; url[i]; ++i) {
  • trunk/Source/WebCore/platform/URL.h

    r205782 r206076  
    2424 */
    2525
    26 #ifndef URL_h
    27 #define URL_h
     26#pragma once
    2827
    2928#include "PlatformExportMacros.h"
     
    131130    // terminated ASCII argument. The argument must be lower-case.
    132131    WEBCORE_EXPORT bool protocolIs(const char*) const;
     132    bool protocolIs(const LChar*, size_t) const;
    133133    bool protocolIsBlob() const { return protocolIs("blob"); }
    134134    bool protocolIsData() const { return protocolIs("data"); }
     
    456456
    457457} // namespace WTF
    458 
    459 #endif // URL_h
  • trunk/Source/WebCore/platform/URLParser.cpp

    r206075 r206076  
    950950                if (isSpecialScheme(urlScheme)) {
    951951                    m_urlIsSpecial = true;
    952                     // FIXME: This is unnecessarily allocating a String.
    953                     // This should be easy to optimize once https://bugs.webkit.org/show_bug.cgi?id=162035 lands.
    954                     if (base.protocol() == urlScheme)
     952                    if (base.protocolIs(m_asciiBuffer.data(), m_asciiBuffer.size() - 1))
    955953                        state = State::SpecialRelativeOrAuthority;
    956954                    else
     
    10061004                break;
    10071005            }
    1008             if (base.protocol() != "file") {
     1006            if (!base.protocolIs("file")) {
    10091007                state = State::Relative;
    10101008                break;
     
    14431441    case State::File:
    14441442        LOG_FINAL_STATE("File");
    1445         if (!base.isNull() && base.protocol() == "file") {
     1443        if (!base.isNull() && base.protocolIs("file")) {
    14461444            copyURLPartsUntil(base, URLPart::QueryEnd);
    14471445            m_asciiBuffer.append(':');
Note: See TracChangeset for help on using the changeset viewer.