Title: [233742] trunk
Revision
233742
Author
commit-qu...@webkit.org
Date
2018-07-11 13:48:49 -0700 (Wed, 11 Jul 2018)

Log Message

Reduce size of WebCore::URL
https://bugs.webkit.org/show_bug.cgi?id=186820

Patch by Alex Christensen <achristen...@webkit.org> on 2018-07-11
Reviewed by Yusuke Suzuki.

Source/WebCore:

We were using 32 bits for the length of the port, which is always between 0 and 5 inclusive
because port numbers are missing or between 0 and 65535.  Let's just use 3 bits here.
We were using 32 bits for the length of the scheme, which is usually 3-5 characters and can be
longer for some custom schemes, but I've never seen one more than 20 characters.  If we assume
schemes are always less than 64MB, we can save 8 bytes per URL!

No change in behavior, just less memory use!

* platform/URL.cpp:
(WebCore::URL::invalidate):
(WebCore::URL::lastPathComponent const):
(WebCore::URL::port const):
(WebCore::URL::protocolHostAndPort const):
(WebCore::URL::path const):
(WebCore::URL::removePort):
(WebCore::URL::setPort):
(WebCore::URL::setHostAndPort):
(WebCore::URL::setPath):
* platform/URL.h:
(WebCore::URL::encode const):
(WebCore::URL::decode):
(WebCore::URL::hasPath const):
(WebCore::URL::pathStart const):
* platform/URLParser.cpp:
(WebCore::URLParser::copyBaseWindowsDriveLetter):
(WebCore::URLParser::urlLengthUntilPart):
(WebCore::URLParser::copyURLPartsUntil):
(WebCore::URLParser::shouldPopPath):
(WebCore::URLParser::popPath):
(WebCore::URLParser::parse):
(WebCore::URLParser::parsePort):
(WebCore::URLParser::parseHostAndPort):
(WebCore::URLParser::allValuesEqual):
(WebCore::URLParser::internalValuesConsistent):

Tools:

* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (233741 => 233742)


--- trunk/Source/WebCore/ChangeLog	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Source/WebCore/ChangeLog	2018-07-11 20:48:49 UTC (rev 233742)
@@ -1,3 +1,45 @@
+2018-07-11  Alex Christensen  <achristen...@webkit.org>
+
+        Reduce size of WebCore::URL
+        https://bugs.webkit.org/show_bug.cgi?id=186820
+
+        Reviewed by Yusuke Suzuki.
+
+        We were using 32 bits for the length of the port, which is always between 0 and 5 inclusive
+        because port numbers are missing or between 0 and 65535.  Let's just use 3 bits here.
+        We were using 32 bits for the length of the scheme, which is usually 3-5 characters and can be
+        longer for some custom schemes, but I've never seen one more than 20 characters.  If we assume
+        schemes are always less than 64MB, we can save 8 bytes per URL!
+
+        No change in behavior, just less memory use!
+
+        * platform/URL.cpp:
+        (WebCore::URL::invalidate):
+        (WebCore::URL::lastPathComponent const):
+        (WebCore::URL::port const):
+        (WebCore::URL::protocolHostAndPort const):
+        (WebCore::URL::path const):
+        (WebCore::URL::removePort):
+        (WebCore::URL::setPort):
+        (WebCore::URL::setHostAndPort):
+        (WebCore::URL::setPath):
+        * platform/URL.h:
+        (WebCore::URL::encode const):
+        (WebCore::URL::decode):
+        (WebCore::URL::hasPath const):
+        (WebCore::URL::pathStart const):
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::copyBaseWindowsDriveLetter):
+        (WebCore::URLParser::urlLengthUntilPart):
+        (WebCore::URLParser::copyURLPartsUntil):
+        (WebCore::URLParser::shouldPopPath):
+        (WebCore::URLParser::popPath):
+        (WebCore::URLParser::parse):
+        (WebCore::URLParser::parsePort):
+        (WebCore::URLParser::parseHostAndPort):
+        (WebCore::URLParser::allValuesEqual):
+        (WebCore::URLParser::internalValuesConsistent):
+
 2018-07-11  Youenn Fablet  <you...@apple.com>
 
         Fix remaining Cross-Origin-Resource-Policy failures, if any

Modified: trunk/Source/WebCore/platform/URL.cpp (233741 => 233742)


--- trunk/Source/WebCore/platform/URL.cpp	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Source/WebCore/platform/URL.cpp	2018-07-11 20:48:49 UTC (rev 233742)
@@ -84,7 +84,7 @@
     m_userEnd = 0;
     m_passwordEnd = 0;
     m_hostEnd = 0;
-    m_portEnd = 0;
+    m_portLength = 0;
     m_pathEnd = 0;
     m_pathAfterLastSlash = 0;
     m_queryEnd = 0;
@@ -144,7 +144,7 @@
         --end;
 
     size_t start = m_string.reverseFind('/', end);
-    if (start < static_cast<unsigned>(m_portEnd))
+    if (start < static_cast<unsigned>(m_hostEnd + m_portLength))
         return String();
     ++start;
 
@@ -164,15 +164,15 @@
 
 std::optional<uint16_t> URL::port() const
 {
-    if (!m_portEnd || m_hostEnd >= m_portEnd - 1)
+    if (!m_portLength)
         return std::nullopt;
 
     bool ok = false;
     unsigned number;
     if (m_string.is8Bit())
-        number = charactersToUIntStrict(m_string.characters8() + m_hostEnd + 1, m_portEnd - m_hostEnd - 1, &ok);
+        number = charactersToUIntStrict(m_string.characters8() + m_hostEnd + 1, m_portLength - 1, &ok);
     else
-        number = charactersToUIntStrict(m_string.characters16() + m_hostEnd + 1, m_portEnd - m_hostEnd - 1, &ok);
+        number = charactersToUIntStrict(m_string.characters16() + m_hostEnd + 1, m_portLength - 1, &ok);
     if (!ok || number > std::numeric_limits<uint16_t>::max())
         return std::nullopt;
     return number;
@@ -187,7 +187,7 @@
 
 String URL::protocolHostAndPort() const
 {
-    String result = m_string.substring(0, m_portEnd);
+    String result = m_string.substring(0, m_hostEnd + m_portLength);
 
     if (m_passwordEnd - m_userStart > 0) {
         const int allowForTrailingAtSign = 1;
@@ -370,7 +370,8 @@
 
 String URL::path() const
 {
-    return m_string.substring(m_portEnd, m_pathEnd - m_portEnd);
+    unsigned portEnd = m_hostEnd + m_portLength;
+    return m_string.substring(portEnd, m_pathEnd - portEnd);
 }
 
 bool URL::setProtocol(const String& s)
@@ -455,9 +456,9 @@
 
 void URL::removePort()
 {
-    if (m_hostEnd == m_portEnd)
+    if (!m_portLength)
         return;
-    URLParser parser(m_string.left(m_hostEnd) + m_string.substring(m_portEnd));
+    URLParser parser(m_string.left(m_hostEnd) + m_string.substring(m_hostEnd + m_portLength));
     *this = parser.result();
 }
 
@@ -466,10 +467,10 @@
     if (!m_isValid)
         return;
 
-    bool colonNeeded = m_portEnd == m_hostEnd;
+    bool colonNeeded = !m_portLength;
     unsigned portStart = (colonNeeded ? m_hostEnd : m_hostEnd + 1);
 
-    URLParser parser(makeString(m_string.left(portStart), (colonNeeded ? ":" : ""), String::number(i), m_string.substring(m_portEnd)));
+    URLParser parser(makeString(m_string.left(portStart), (colonNeeded ? ":" : ""), String::number(i), m_string.substring(m_hostEnd + m_portLength)));
     *this = parser.result();
 }
 
@@ -509,7 +510,7 @@
         builder.appendLiteral(":");
         builder.append(port);
     }
-    builder.append(m_string.substring(m_portEnd));
+    builder.append(m_string.substring(m_hostEnd + m_portLength));
 
     URLParser parser(builder.toString());
     *this = parser.result();
@@ -658,7 +659,7 @@
     auto questionMarkOrNumberSign = [] (UChar character) {
         return character == '?' || character == '#';
     };
-    URLParser parser(makeString(StringView(m_string).left(m_portEnd), percentEncodeCharacters(path, questionMarkOrNumberSign), StringView(m_string).substring(m_pathEnd)));
+    URLParser parser(makeString(StringView(m_string).left(m_hostEnd + m_portLength), percentEncodeCharacters(path, questionMarkOrNumberSign), StringView(m_string).substring(m_pathEnd)));
     *this = parser.result();
 }
 

Modified: trunk/Source/WebCore/platform/URL.h (233741 => 233742)


--- trunk/Source/WebCore/platform/URL.h	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Source/WebCore/platform/URL.h	2018-07-11 20:48:49 UTC (rev 233742)
@@ -219,21 +219,28 @@
     void copyToBuffer(Vector<char, 512>& buffer) const;
 
     String m_string;
-    bool m_isValid : 1;
-    bool m_protocolIsInHTTPFamily : 1;
-    bool m_cannotBeABaseURL : 1;
 
-    unsigned m_schemeEnd;
+    unsigned m_isValid : 1;
+    unsigned m_protocolIsInHTTPFamily : 1;
+    unsigned m_cannotBeABaseURL : 1;
+
+    // This is out of order to allign the bits better. The port is after the host.
+    unsigned m_portLength : 3;
+    static constexpr unsigned maxPortLength = (1 << 3) - 1;
+
+    static constexpr unsigned maxSchemeLength = (1 << 26) - 1;
+    unsigned m_schemeEnd : 26;
     unsigned m_userStart;
     unsigned m_userEnd;
     unsigned m_passwordEnd;
     unsigned m_hostEnd;
-    unsigned m_portEnd;
     unsigned m_pathAfterLastSlash;
     unsigned m_pathEnd;
     unsigned m_queryEnd;
 };
 
+static_assert(sizeof(URL) == sizeof(String) + 8 * sizeof(unsigned), "URL should stay small");
+
 template <class Encoder>
 void URL::encode(Encoder& encoder) const
 {
@@ -242,12 +249,13 @@
     if (!m_isValid)
         return;
     encoder << static_cast<bool>(m_protocolIsInHTTPFamily);
-    encoder << m_schemeEnd;
+    encoder << static_cast<bool>(m_cannotBeABaseURL);
+    encoder << static_cast<unsigned>(m_schemeEnd);
     encoder << m_userStart;
     encoder << m_userEnd;
     encoder << m_passwordEnd;
     encoder << m_hostEnd;
-    encoder << m_portEnd;
+    encoder << static_cast<unsigned>(m_portLength);
     encoder << m_pathAfterLastSlash;
     encoder << m_pathEnd;
     encoder << m_queryEnd;
@@ -279,8 +287,18 @@
     if (!decoder.decode(protocolIsInHTTPFamily))
         return std::nullopt;
     url.m_protocolIsInHTTPFamily = protocolIsInHTTPFamily;
-    if (!decoder.decode(url.m_schemeEnd))
+    bool cannotBeABaseURL;
+    if (!decoder.decode(cannotBeABaseURL))
         return std::nullopt;
+    url.m_cannotBeABaseURL = cannotBeABaseURL;
+    unsigned schemeEnd;
+    if (!decoder.decode(schemeEnd))
+        return std::nullopt;
+    if (schemeEnd >= maxSchemeLength) {
+        ASSERT_NOT_REACHED();
+        return std::nullopt;
+    }
+    url.m_schemeEnd = schemeEnd;
     if (!decoder.decode(url.m_userStart))
         return std::nullopt;
     if (!decoder.decode(url.m_userEnd))
@@ -289,8 +307,14 @@
         return std::nullopt;
     if (!decoder.decode(url.m_hostEnd))
         return std::nullopt;
-    if (!decoder.decode(url.m_portEnd))
+    unsigned portLength;
+    if (!decoder.decode(portLength))
         return std::nullopt;
+    if (portLength > maxPortLength) {
+        ASSERT_NOT_REACHED();
+        return std::nullopt;
+    }
+    url.m_portLength = portLength;
     if (!decoder.decode(url.m_pathAfterLastSlash))
         return std::nullopt;
     if (!decoder.decode(url.m_pathEnd))
@@ -400,7 +424,7 @@
 
 inline bool URL::hasPath() const
 {
-    return m_pathEnd != m_portEnd;
+    return m_pathEnd != m_hostEnd + m_portLength;
 }
 
 inline bool URL::hasUsername() const
@@ -440,7 +464,7 @@
 
 inline unsigned URL::pathStart() const
 {
-    return m_portEnd;
+    return m_hostEnd + m_portLength;
 }
 
 inline unsigned URL::pathEnd() const

Modified: trunk/Source/WebCore/platform/URLParser.cpp (233741 => 233742)


--- trunk/Source/WebCore/platform/URLParser.cpp	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2018-07-11 20:48:49 UTC (rev 233742)
@@ -502,10 +502,10 @@
 bool URLParser::copyBaseWindowsDriveLetter(const URL& base)
 {
     if (base.protocolIs("file")) {
-        RELEASE_ASSERT(base.m_portEnd < base.m_string.length());
+        RELEASE_ASSERT(base.m_hostEnd + base.m_portLength < base.m_string.length());
         if (base.m_string.is8Bit()) {
             const LChar* begin = base.m_string.characters8();
-            CodePointIterator<LChar> c(begin + base.m_portEnd + 1, begin + base.m_string.length());
+            CodePointIterator<LChar> c(begin + base.m_hostEnd + base.m_portLength + 1, begin + base.m_string.length());
             if (isWindowsDriveLetter(c)) {
                 appendWindowsDriveLetter(c);
                 return true;
@@ -512,7 +512,7 @@
             }
         } else {
             const UChar* begin = base.m_string.characters16();
-            CodePointIterator<UChar> c(begin + base.m_portEnd + 1, begin + base.m_string.length());
+            CodePointIterator<UChar> c(begin + base.m_hostEnd + base.m_portLength + 1, begin + base.m_string.length());
             if (isWindowsDriveLetter(c)) {
                 appendWindowsDriveLetter(c);
                 return true;
@@ -846,7 +846,7 @@
     case URLPart::PathAfterLastSlash:
         return url.m_pathAfterLastSlash;
     case URLPart::PortEnd:
-        return url.m_portEnd;
+        return url.m_hostEnd + url.m_portLength;
     case URLPart::HostEnd:
         return url.m_hostEnd;
     case URLPart::PasswordEnd:
@@ -898,7 +898,7 @@
         m_url.m_pathAfterLastSlash = base.m_pathAfterLastSlash;
         FALLTHROUGH;
     case URLPart::PortEnd:
-        m_url.m_portEnd = base.m_portEnd;
+        m_url.m_portLength = base.m_portLength;
         FALLTHROUGH;
     case URLPart::HostEnd:
         m_url.m_hostEnd = base.m_hostEnd;
@@ -1043,7 +1043,7 @@
 
     ASSERT(m_url.m_pathAfterLastSlash <= m_asciiBuffer.size());
     CodePointIterator<LChar> componentToPop(&m_asciiBuffer[newPathAfterLastSlash], &m_asciiBuffer[0] + m_url.m_pathAfterLastSlash);
-    if (newPathAfterLastSlash == m_url.m_portEnd + 1 && isWindowsDriveLetter(componentToPop))
+    if (newPathAfterLastSlash == m_url.m_hostEnd + m_url.m_portLength + 1 && isWindowsDriveLetter(componentToPop))
         return false;
     return true;
 }
@@ -1051,11 +1051,11 @@
 void URLParser::popPath()
 {
     ASSERT(m_didSeeSyntaxViolation);
-    if (m_url.m_pathAfterLastSlash > m_url.m_portEnd + 1) {
+    if (m_url.m_pathAfterLastSlash > m_url.m_hostEnd + m_url.m_portLength + 1) {
         auto newPathAfterLastSlash = m_url.m_pathAfterLastSlash - 1;
         if (m_asciiBuffer[newPathAfterLastSlash] == '/')
             newPathAfterLastSlash--;
-        while (newPathAfterLastSlash > m_url.m_portEnd && m_asciiBuffer[newPathAfterLastSlash] != '/')
+        while (newPathAfterLastSlash > m_url.m_hostEnd + m_url.m_portLength && m_asciiBuffer[newPathAfterLastSlash] != '/')
             newPathAfterLastSlash--;
         newPathAfterLastSlash++;
         if (shouldPopPath(newPathAfterLastSlash))
@@ -1271,7 +1271,12 @@
                     syntaxViolation(c);
                 appendToASCIIBuffer(toASCIILower(*c));
             } else if (*c == ':') {
-                m_url.m_schemeEnd = currentPosition(c);
+                unsigned schemeEnd = currentPosition(c);
+                if (schemeEnd > URL::maxSchemeLength) {
+                    failure();
+                    return;
+                }
+                m_url.m_schemeEnd = schemeEnd;
                 StringView urlScheme = parsedDataView(0, m_url.m_schemeEnd);
                 appendToASCIIBuffer(':');
                 switch (scheme(urlScheme)) {
@@ -1321,7 +1326,7 @@
                         m_url.m_userEnd = m_url.m_userStart;
                         m_url.m_passwordEnd = m_url.m_userStart;
                         m_url.m_hostEnd = m_url.m_userStart;
-                        m_url.m_portEnd = m_url.m_userStart;
+                        m_url.m_portLength = 0;
                         m_url.m_pathAfterLastSlash = m_url.m_userStart;
                         m_url.m_cannotBeABaseURL = true;
                         state = State::CannotBeABaseURLPath;
@@ -1395,7 +1400,7 @@
                 m_url.m_userEnd = m_url.m_userStart;
                 m_url.m_passwordEnd = m_url.m_userStart;
                 m_url.m_hostEnd = m_url.m_userStart;
-                m_url.m_portEnd = m_url.m_userStart;
+                m_url.m_portLength = 0;
                 m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
                 state = State::Path;
             }
@@ -1451,7 +1456,7 @@
             } else {
                 copyURLPartsUntil(base, URLPart::PortEnd, c, isUTF8Encoding);
                 appendToASCIIBuffer('/');
-                m_url.m_pathAfterLastSlash = base.m_portEnd + 1;
+                m_url.m_pathAfterLastSlash = base.m_hostEnd + base.m_portLength + 1;
                 state = State::Path;
             }
             break;
@@ -1520,7 +1525,7 @@
                         m_url.m_userEnd = currentPosition(c);
                         m_url.m_passwordEnd = m_url.m_userEnd;
                         m_url.m_hostEnd = m_url.m_userEnd;
-                        m_url.m_portEnd = m_url.m_userEnd;
+                        m_url.m_portLength = 0;
                         m_url.m_pathAfterLastSlash = m_url.m_userEnd;
                     } else {
                         m_url.m_userEnd = currentPosition(authorityOrHostBegin);
@@ -1590,7 +1595,7 @@
                     m_url.m_userEnd = m_url.m_userStart;
                     m_url.m_passwordEnd = m_url.m_userStart;
                     m_url.m_hostEnd = m_url.m_userStart;
-                    m_url.m_portEnd = m_url.m_userStart;
+                    m_url.m_portLength = 0;
                     m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
                     m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
                 }
@@ -1612,7 +1617,7 @@
                     m_url.m_userEnd = m_url.m_userStart;
                     m_url.m_passwordEnd = m_url.m_userStart;
                     m_url.m_hostEnd = m_url.m_userStart;
-                    m_url.m_portEnd = m_url.m_userStart;
+                    m_url.m_portLength = 0;
                     m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
                     m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
                     m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
@@ -1630,7 +1635,7 @@
                     m_url.m_userEnd = m_url.m_userStart;
                     m_url.m_passwordEnd = m_url.m_userStart;
                     m_url.m_hostEnd = m_url.m_userStart;
-                    m_url.m_portEnd = m_url.m_userStart;
+                    m_url.m_portLength = 0;
                     m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
                     if (isWindowsDriveLetter(c))
                         appendWindowsDriveLetter(c);
@@ -1650,7 +1655,7 @@
                 m_url.m_userEnd = m_url.m_userStart;
                 m_url.m_passwordEnd = m_url.m_userStart;
                 m_url.m_hostEnd = m_url.m_userStart;
-                m_url.m_portEnd = m_url.m_userStart;
+                m_url.m_portLength = 0;
                 authorityOrHostBegin = c;
                 state = State::FileHost;
                 break;
@@ -1661,7 +1666,7 @@
             m_url.m_userEnd = m_url.m_userStart;
             m_url.m_passwordEnd = m_url.m_userStart;
             m_url.m_hostEnd = m_url.m_userStart;
-            m_url.m_portEnd = m_url.m_userStart;
+            m_url.m_portLength = 0;
             if (isWindowsDriveLetter(c)) {
                 appendWindowsDriveLetter(c);
                 m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
@@ -1720,7 +1725,7 @@
                         syntaxViolation(c);
                         m_asciiBuffer.shrink(m_url.m_passwordEnd);
                         m_url.m_hostEnd = currentPosition(c);
-                        m_url.m_portEnd = m_url.m_hostEnd;
+                        m_url.m_portLength = 0;
                     }
                     
                     state = State::PathStart;
@@ -1875,7 +1880,7 @@
         m_url.m_userEnd = m_url.m_userStart;
         m_url.m_passwordEnd = m_url.m_userStart;
         m_url.m_hostEnd = m_url.m_userStart;
-        m_url.m_portEnd = m_url.m_userStart;
+        m_url.m_portLength = 0;
         m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
@@ -1887,7 +1892,7 @@
         LOG_FINAL_STATE("RelativeSlash");
         copyURLPartsUntil(base, URLPart::PortEnd, c, isUTF8Encoding);
         appendToASCIIBuffer('/');
-        m_url.m_pathAfterLastSlash = base.m_portEnd + 1;
+        m_url.m_pathAfterLastSlash = m_url.m_hostEnd + m_url.m_portLength + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
         break;
@@ -1897,7 +1902,7 @@
         m_url.m_userEnd = m_url.m_userStart;
         m_url.m_passwordEnd = m_url.m_userStart;
         m_url.m_hostEnd = m_url.m_userStart;
-        m_url.m_portEnd = m_url.m_userStart;
+        m_url.m_portLength = 0;
         m_url.m_pathAfterLastSlash = m_url.m_userStart;
         m_url.m_pathEnd = m_url.m_userStart;
         m_url.m_queryEnd = m_url.m_userStart;
@@ -1914,7 +1919,7 @@
             m_url.m_userEnd = m_url.m_userStart;
             m_url.m_passwordEnd = m_url.m_userStart;
             m_url.m_hostEnd = m_url.m_userStart;
-            m_url.m_portEnd = m_url.m_userStart;
+            m_url.m_portLength = 0;
             m_url.m_pathEnd = m_url.m_userStart;
         } else if (!parseHostAndPort(authorityOrHostBegin)) {
             failure();
@@ -1923,9 +1928,9 @@
             if (m_urlIsSpecial) {
                 syntaxViolation(c);
                 appendToASCIIBuffer('/');
-                m_url.m_pathEnd = m_url.m_portEnd + 1;
+                m_url.m_pathEnd = m_url.m_hostEnd + m_url.m_portLength + 1;
             } else
-                m_url.m_pathEnd = m_url.m_portEnd;
+                m_url.m_pathEnd = m_url.m_hostEnd + m_url.m_portLength;
         }
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
         m_url.m_queryEnd = m_url.m_pathEnd;
@@ -1939,9 +1944,9 @@
         if (m_urlIsSpecial) {
             syntaxViolation(c);
             appendToASCIIBuffer('/');
-            m_url.m_pathEnd = m_url.m_portEnd + 1;
+            m_url.m_pathEnd = m_url.m_hostEnd + m_url.m_portLength + 1;
         } else
-            m_url.m_pathEnd = m_url.m_portEnd;
+            m_url.m_pathEnd = m_url.m_hostEnd + m_url.m_portLength;
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
         m_url.m_queryEnd = m_url.m_pathEnd;
         break;
@@ -1957,7 +1962,7 @@
         m_url.m_userEnd = m_url.m_userStart;
         m_url.m_passwordEnd = m_url.m_userStart;
         m_url.m_hostEnd = m_url.m_userStart;
-        m_url.m_portEnd = m_url.m_userStart;
+        m_url.m_portLength = 0;
         m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
@@ -1970,7 +1975,7 @@
         m_url.m_userEnd = m_url.m_userStart;
         m_url.m_passwordEnd = m_url.m_userStart;
         m_url.m_hostEnd = m_url.m_userStart;
-        m_url.m_portEnd = m_url.m_userStart;
+        m_url.m_portLength = 0;
         if (copyBaseWindowsDriveLetter(base)) {
             appendToASCIIBuffer('/');
             m_url.m_pathAfterLastSlash = m_url.m_userStart + 4;
@@ -1999,7 +2004,7 @@
             m_url.m_userEnd = m_url.m_userStart;
             m_url.m_passwordEnd = m_url.m_userStart;
             m_url.m_hostEnd = m_url.m_userStart;
-            m_url.m_portEnd = m_url.m_userStart;
+            m_url.m_portLength = 0;
             m_url.m_pathAfterLastSlash = m_url.m_userStart + 1;
             m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
             m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
@@ -2015,10 +2020,10 @@
         if (isLocalhost(parsedDataView(m_url.m_passwordEnd, currentPosition(c) - m_url.m_passwordEnd))) {
             m_asciiBuffer.shrink(m_url.m_passwordEnd);
             m_url.m_hostEnd = currentPosition(c);
-            m_url.m_portEnd = m_url.m_hostEnd;
+            m_url.m_portLength = 0;
         }
         appendToASCIIBuffer('/');
-        m_url.m_pathAfterLastSlash = m_url.m_portEnd + 1;
+        m_url.m_pathAfterLastSlash = m_url.m_hostEnd + m_url.m_portLength + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
         break;
@@ -2601,7 +2606,9 @@
     advance(iterator, colonIterator);
     uint32_t port = 0;
     if (UNLIKELY(iterator.atEnd())) {
-        m_url.m_portEnd = currentPosition(colonIterator);
+        unsigned portLength = currentPosition(colonIterator) - m_url.m_hostEnd;
+        RELEASE_ASSERT(portLength <= URL::maxPortLength);
+        m_url.m_portLength = portLength;
         syntaxViolation(colonIterator);
         return true;
     }
@@ -2638,7 +2645,9 @@
         appendNumberToASCIIBuffer<uint16_t>(static_cast<uint16_t>(port));
     }
 
-    m_url.m_portEnd = currentPosition(iterator);
+    unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
+    RELEASE_ASSERT(portLength <= URL::maxPortLength);
+    m_url.m_portLength = portLength;
     return true;
 }
 
@@ -2664,7 +2673,7 @@
                     return parsePort(ipv6End);
                 }
                 m_url.m_hostEnd = currentPosition(ipv6End);
-                m_url.m_portEnd = m_url.m_hostEnd;
+                m_url.m_portLength = 0;
                 return true;
             }
             m_url.m_hostEnd = currentPosition(ipv6End);
@@ -2687,7 +2696,7 @@
         }
         m_url.m_hostEnd = currentPosition(iterator);
         if (iterator.atEnd()) {
-            m_url.m_portEnd = currentPosition(iterator);
+            m_url.m_portLength = 0;
             return true;
         }
         return parsePort(iterator);
@@ -2708,7 +2717,7 @@
             serializeIPv4(address.value());
             m_url.m_hostEnd = currentPosition(iterator);
             if (iterator.atEnd()) {
-                m_url.m_portEnd = currentPosition(iterator);
+                m_url.m_portLength = 0;
                 return true;
             }
             return parsePort(iterator);
@@ -2727,7 +2736,9 @@
         m_url.m_hostEnd = currentPosition(iterator);
         if (!hostIterator.atEnd())
             return parsePort(hostIterator);
-        m_url.m_portEnd = currentPosition(iterator);
+        unsigned portLength = currentPosition(iterator) - m_url.m_hostEnd;
+        RELEASE_ASSERT(portLength <= URL::maxPortLength);
+        m_url.m_portLength = portLength;
         return true;
     }
     
@@ -2769,7 +2780,7 @@
         serializeIPv4(address.value());
         m_url.m_hostEnd = currentPosition(iterator);
         if (iterator.atEnd()) {
-            m_url.m_portEnd = currentPosition(iterator);
+            m_url.m_portLength = 0;
             return true;
         }
         return parsePort(iterator);
@@ -2781,7 +2792,7 @@
     m_url.m_hostEnd = currentPosition(iterator);
     if (!iterator.atEnd())
         return parsePort(iterator);
-    m_url.m_portEnd = currentPosition(iterator);
+    m_url.m_portLength = 0;
     return true;
 }
 
@@ -2868,10 +2879,9 @@
 
 bool URLParser::allValuesEqual(const URL& a, const URL& b)
 {
-    // FIXME: m_cannotBeABaseURL is not compared because the old URL::parse did not use it,
-    // but once we get rid of URL::parse its value should be tested.
-    URL_PARSER_LOG("%d %d %d %d %d %d %d %d %d %d %d %s\n%d %d %d %d %d %d %d %d %d %d %d %s",
+    URL_PARSER_LOG("%d %d %d %d %d %d %d %d %d %d %d %d %s\n%d %d %d %d %d %d %d %d %d %d %d %d %s",
         a.m_isValid,
+        a.m_cannotBeABaseURL,
         a.m_protocolIsInHTTPFamily,
         a.m_schemeEnd,
         a.m_userStart,
@@ -2878,12 +2888,13 @@
         a.m_userEnd,
         a.m_passwordEnd,
         a.m_hostEnd,
-        a.m_portEnd,
+        a.m_hostEnd + a.m_portLength,
         a.m_pathAfterLastSlash,
         a.m_pathEnd,
         a.m_queryEnd,
         a.m_string.utf8().data(),
         b.m_isValid,
+        b.m_cannotBeABaseURL,
         b.m_protocolIsInHTTPFamily,
         b.m_schemeEnd,
         b.m_userStart,
@@ -2890,7 +2901,7 @@
         b.m_userEnd,
         b.m_passwordEnd,
         b.m_hostEnd,
-        b.m_portEnd,
+        b.m_hostEnd + b.m_portLength,
         b.m_pathAfterLastSlash,
         b.m_pathEnd,
         b.m_queryEnd,
@@ -2898,6 +2909,7 @@
 
     return a.m_string == b.m_string
         && a.m_isValid == b.m_isValid
+        && a.m_cannotBeABaseURL == b.m_cannotBeABaseURL
         && a.m_protocolIsInHTTPFamily == b.m_protocolIsInHTTPFamily
         && a.m_schemeEnd == b.m_schemeEnd
         && a.m_userStart == b.m_userStart
@@ -2904,7 +2916,7 @@
         && a.m_userEnd == b.m_userEnd
         && a.m_passwordEnd == b.m_passwordEnd
         && a.m_hostEnd == b.m_hostEnd
-        && a.m_portEnd == b.m_portEnd
+        && a.m_portLength == b.m_portLength
         && a.m_pathAfterLastSlash == b.m_pathAfterLastSlash
         && a.m_pathEnd == b.m_pathEnd
         && a.m_queryEnd == b.m_queryEnd;
@@ -2916,8 +2928,7 @@
         && url.m_userStart <= url.m_userEnd
         && url.m_userEnd <= url.m_passwordEnd
         && url.m_passwordEnd <= url.m_hostEnd
-        && url.m_hostEnd <= url.m_portEnd
-        && url.m_portEnd <= url.m_pathAfterLastSlash
+        && url.m_hostEnd + url.m_portLength <= url.m_pathAfterLastSlash
         && url.m_pathAfterLastSlash <= url.m_pathEnd
         && url.m_pathEnd <= url.m_queryEnd
         && url.m_queryEnd <= url.m_string.length();

Modified: trunk/Tools/ChangeLog (233741 => 233742)


--- trunk/Tools/ChangeLog	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Tools/ChangeLog	2018-07-11 20:48:49 UTC (rev 233742)
@@ -1,3 +1,13 @@
+2018-07-11  Alex Christensen  <achristen...@webkit.org>
+
+        Reduce size of WebCore::URL
+        https://bugs.webkit.org/show_bug.cgi?id=186820
+
+        Reviewed by Yusuke Suzuki.
+
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2018-07-11  Youenn Fablet  <you...@apple.com>
 
         Fix remaining Cross-Origin-Resource-Policy failures, if any

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp (233741 => 233742)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2018-07-11 20:47:05 UTC (rev 233741)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp	2018-07-11 20:48:49 UTC (rev 233742)
@@ -1179,6 +1179,9 @@
     checkURLDifferences("file://:0/path",
         {"", "", "", "", 0, "", "", "", "file://:0/path"},
         {"file", "", "", "", 0, "/path", "", "", "file://:0/path"});
+    
+    checkURL("http://example.com:0000000000000077", {"http", "", "", "example.com", 77, "/", "", "", "http://example.com:77/"});
+    checkURL("http://example.com:0000000000000080", {"http", "", "", "example.com", 0, "/", "", "", "http://example.com/"});
 }
 
 TEST_F(URLParserTest, ParserFailures)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to