Title: [219338] trunk/Source/WebCore
Revision
219338
Author
[email protected]
Date
2017-07-11 10:02:14 -0700 (Tue, 11 Jul 2017)

Log Message

Reduce URL size
https://bugs.webkit.org/show_bug.cgi?id=174319

Patch by Alex Christensen <[email protected]> on 2017-07-11
Reviewed by Andreas Kling.

m_fragmentEnd is redundant information. If a URL is valid, then it is always m_string.length().
If a URL is not valid, then it is always 0. Rather than storing additional information,
deduce the fragment end from the validity of the URL and the String's length.

No change in behavior.  This reduces sizeof(URL) from 56 to 48 and reduces operations when parsing.

* platform/URL.cpp:
(WebCore::URL::invalidate):
(WebCore::URL::fragmentIdentifier):
(WebCore::URL::hasFragmentIdentifier):
(WebCore::URL::removeFragmentIdentifier):
* platform/URL.h:
(WebCore::URL::encode):
(WebCore::URL::decode):
(WebCore::URL::hasFragment):
* platform/URLParser.cpp:
(WebCore::URLParser::urlLengthUntilPart):
(WebCore::URLParser::copyURLPartsUntil):
(WebCore::URLParser::parse):
(WebCore::URLParser::allValuesEqual):
(WebCore::URLParser::internalValuesConsistent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (219337 => 219338)


--- trunk/Source/WebCore/ChangeLog	2017-07-11 16:51:27 UTC (rev 219337)
+++ trunk/Source/WebCore/ChangeLog	2017-07-11 17:02:14 UTC (rev 219338)
@@ -1,5 +1,34 @@
 2017-07-11  Alex Christensen  <[email protected]>
 
+        Reduce URL size
+        https://bugs.webkit.org/show_bug.cgi?id=174319
+
+        Reviewed by Andreas Kling.
+
+        m_fragmentEnd is redundant information. If a URL is valid, then it is always m_string.length().
+        If a URL is not valid, then it is always 0. Rather than storing additional information,
+        deduce the fragment end from the validity of the URL and the String's length.
+
+        No change in behavior.  This reduces sizeof(URL) from 56 to 48 and reduces operations when parsing.
+
+        * platform/URL.cpp:
+        (WebCore::URL::invalidate):
+        (WebCore::URL::fragmentIdentifier):
+        (WebCore::URL::hasFragmentIdentifier):
+        (WebCore::URL::removeFragmentIdentifier):
+        * platform/URL.h:
+        (WebCore::URL::encode):
+        (WebCore::URL::decode):
+        (WebCore::URL::hasFragment):
+        * platform/URLParser.cpp:
+        (WebCore::URLParser::urlLengthUntilPart):
+        (WebCore::URLParser::copyURLPartsUntil):
+        (WebCore::URLParser::parse):
+        (WebCore::URLParser::allValuesEqual):
+        (WebCore::URLParser::internalValuesConsistent):
+
+2017-07-11  Alex Christensen  <[email protected]>
+
         SharedBuffer::size should return a size_t
         https://bugs.webkit.org/show_bug.cgi?id=174328
 

Modified: trunk/Source/WebCore/platform/URL.cpp (219337 => 219338)


--- trunk/Source/WebCore/platform/URL.cpp	2017-07-11 16:51:27 UTC (rev 219337)
+++ trunk/Source/WebCore/platform/URL.cpp	2017-07-11 17:02:14 UTC (rev 219338)
@@ -355,7 +355,6 @@
     m_pathEnd = 0;
     m_pathAfterLastSlash = 0;
     m_queryEnd = 0;
-    m_fragmentEnd = 0;
 }
 
 URL::URL(ParsedURLStringTag, const String& url)
@@ -493,15 +492,15 @@
 
 String URL::fragmentIdentifier() const
 {
-    if (m_fragmentEnd == m_queryEnd)
+    if (!m_isValid || m_queryEnd == m_string.length())
         return String();
 
-    return m_string.substring(m_queryEnd + 1, m_fragmentEnd - (m_queryEnd + 1));
+    return m_string.substring(m_queryEnd + 1);
 }
 
 bool URL::hasFragmentIdentifier() const
 {
-    return m_fragmentEnd != m_queryEnd;
+    return m_isValid && m_string.length() != m_queryEnd;
 }
 
 String URL::baseAsString() const
@@ -864,13 +863,11 @@
 void URL::removeFragmentIdentifier()
 {
     if (!m_isValid) {
-        ASSERT(!m_fragmentEnd);
         ASSERT(!m_queryEnd);
         return;
     }
-    if (m_fragmentEnd > m_queryEnd)
+    if (m_isValid && m_string.length() > m_queryEnd)
         m_string = m_string.left(m_queryEnd);
-    m_fragmentEnd = m_queryEnd;
 }
     
 void URL::setQuery(const String& query)

Modified: trunk/Source/WebCore/platform/URL.h (219337 => 219338)


--- trunk/Source/WebCore/platform/URL.h	2017-07-11 16:51:27 UTC (rev 219337)
+++ trunk/Source/WebCore/platform/URL.h	2017-07-11 17:02:14 UTC (rev 219338)
@@ -231,7 +231,6 @@
     unsigned m_pathAfterLastSlash;
     unsigned m_pathEnd;
     unsigned m_queryEnd;
-    unsigned m_fragmentEnd;
 };
 
 template <class Encoder>
@@ -251,7 +250,6 @@
     encoder << m_pathAfterLastSlash;
     encoder << m_pathEnd;
     encoder << m_queryEnd;
-    encoder << m_fragmentEnd;
 }
 
 template <class Decoder>
@@ -287,8 +285,6 @@
         return false;
     if (!decoder.decode(url.m_queryEnd))
         return false;
-    if (!decoder.decode(url.m_fragmentEnd))
-        return false;
     return true;
 }
 
@@ -412,7 +408,7 @@
 
 inline bool URL::hasFragment() const
 {
-    return m_fragmentEnd > m_queryEnd;
+    return m_isValid && m_string.length() > m_queryEnd;
 }
 
 inline bool URL::protocolIsInHTTPFamily() const

Modified: trunk/Source/WebCore/platform/URLParser.cpp (219337 => 219338)


--- trunk/Source/WebCore/platform/URLParser.cpp	2017-07-11 16:51:27 UTC (rev 219337)
+++ trunk/Source/WebCore/platform/URLParser.cpp	2017-07-11 17:02:14 UTC (rev 219338)
@@ -829,14 +829,11 @@
     PathAfterLastSlash,
     PathEnd,
     QueryEnd,
-    FragmentEnd,
 };
 
 size_t URLParser::urlLengthUntilPart(const URL& url, URLPart part)
 {
     switch (part) {
-    case URLPart::FragmentEnd:
-        return url.m_fragmentEnd;
     case URLPart::QueryEnd:
         return url.m_queryEnd;
     case URLPart::PathEnd:
@@ -886,8 +883,6 @@
     m_asciiBuffer.clear();
     copyASCIIStringUntil(base.m_string, urlLengthUntilPart(base, part));
     switch (part) {
-    case URLPart::FragmentEnd:
-        RELEASE_ASSERT_NOT_REACHED();
     case URLPart::QueryEnd:
         m_url.m_queryEnd = base.m_queryEnd;
         FALLTHROUGH;
@@ -1861,7 +1856,6 @@
     case State::SpecialRelativeOrAuthority:
         LOG_FINAL_STATE("SpecialRelativeOrAuthority");
         copyURLPartsUntil(base, URLPart::QueryEnd, c, isUTF8Encoding);
-        m_url.m_fragmentEnd = m_url.m_queryEnd;
         break;
     case State::PathOrAuthority:
         LOG_FINAL_STATE("PathOrAuthority");
@@ -1876,7 +1870,6 @@
         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;
-        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
         break;
     case State::Relative:
         LOG_FINAL_STATE("Relative");
@@ -1888,7 +1881,6 @@
         m_url.m_pathAfterLastSlash = base.m_portEnd + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
-        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
         break;
     case State::SpecialAuthoritySlashes:
         LOG_FINAL_STATE("SpecialAuthoritySlashes");
@@ -1900,7 +1892,6 @@
         m_url.m_pathAfterLastSlash = m_url.m_userStart;
         m_url.m_pathEnd = m_url.m_userStart;
         m_url.m_queryEnd = m_url.m_userStart;
-        m_url.m_fragmentEnd = m_url.m_userStart;
         break;
     case State::SpecialAuthorityIgnoreSlashes:
         LOG_FINAL_STATE("SpecialAuthorityIgnoreSlashes");
@@ -1929,7 +1920,6 @@
         }
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
         m_url.m_queryEnd = m_url.m_pathEnd;
-        m_url.m_fragmentEnd = m_url.m_pathEnd;
         break;
     case State::Host:
         LOG_FINAL_STATE("Host");
@@ -1945,13 +1935,11 @@
             m_url.m_pathEnd = m_url.m_portEnd;
         m_url.m_pathAfterLastSlash = m_url.m_pathEnd;
         m_url.m_queryEnd = m_url.m_pathEnd;
-        m_url.m_fragmentEnd = m_url.m_pathEnd;
         break;
     case State::File:
         LOG_FINAL_STATE("File");
         if (base.isValid() && base.protocolIs("file")) {
             copyURLPartsUntil(base, URLPart::QueryEnd, c, isUTF8Encoding);
-            m_url.m_fragmentEnd = m_url.m_queryEnd;
             break;
         }
         syntaxViolation(c);
@@ -1964,7 +1952,6 @@
         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;
-        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
         break;
     case State::FileSlash:
         LOG_FINAL_STATE("FileSlash");
@@ -1982,7 +1969,6 @@
             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;
-        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
         break;
     case State::FileHost:
         LOG_FINAL_STATE("FileHost");
@@ -1994,7 +1980,6 @@
             m_url.m_pathAfterLastSlash = currentPosition(c);
             m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
             m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
-            m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
             break;
         }
         
@@ -2009,7 +1994,6 @@
             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;
-            m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
             break;
         }
 
@@ -2028,7 +2012,6 @@
         m_url.m_pathAfterLastSlash = m_url.m_portEnd + 1;
         m_url.m_pathEnd = m_url.m_pathAfterLastSlash;
         m_url.m_queryEnd = m_url.m_pathAfterLastSlash;
-        m_url.m_fragmentEnd = m_url.m_pathAfterLastSlash;
         break;
     case State::PathStart:
         LOG_FINAL_STATE("PathStart");
@@ -2037,19 +2020,16 @@
         LOG_FINAL_STATE("Path");
         m_url.m_pathEnd = currentPosition(c);
         m_url.m_queryEnd = m_url.m_pathEnd;
-        m_url.m_fragmentEnd = m_url.m_pathEnd;
         break;
     case State::CannotBeABaseURLPath:
         LOG_FINAL_STATE("CannotBeABaseURLPath");
         m_url.m_pathEnd = currentPosition(c);
         m_url.m_queryEnd = m_url.m_pathEnd;
-        m_url.m_fragmentEnd = m_url.m_pathEnd;
         break;
     case State::UTF8Query:
         LOG_FINAL_STATE("UTF8Query");
         ASSERT(queryBegin == CodePointIterator<CharacterType>());
         m_url.m_queryEnd = currentPosition(c);
-        m_url.m_fragmentEnd = m_url.m_queryEnd;
         break;
     case State::NonUTF8Query:
         LOG_FINAL_STATE("NonUTF8Query");
@@ -2056,11 +2036,9 @@
         ASSERT(queryBegin != CodePointIterator<CharacterType>());
         encodeQuery(queryBuffer, encoding, CodePointIterator<CharacterType>(queryBegin, c));
         m_url.m_queryEnd = currentPosition(c);
-        m_url.m_fragmentEnd = m_url.m_queryEnd;
         break;
     case State::Fragment:
         LOG_FINAL_STATE("Fragment");
-        m_url.m_fragmentEnd = currentPosition(c);
         break;
     }
 
@@ -2887,7 +2865,7 @@
 {
     // 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 %d %s\n%d %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 %s\n%d %d %d %d %d %d %d %d %d %d %d %s",
         a.m_isValid,
         a.m_protocolIsInHTTPFamily,
         a.m_schemeEnd,
@@ -2899,7 +2877,6 @@
         a.m_pathAfterLastSlash,
         a.m_pathEnd,
         a.m_queryEnd,
-        a.m_fragmentEnd,
         a.m_string.utf8().data(),
         b.m_isValid,
         b.m_protocolIsInHTTPFamily,
@@ -2912,7 +2889,6 @@
         b.m_pathAfterLastSlash,
         b.m_pathEnd,
         b.m_queryEnd,
-        b.m_fragmentEnd,
         b.m_string.utf8().data());
 
     return a.m_string == b.m_string
@@ -2926,8 +2902,7 @@
         && a.m_portEnd == b.m_portEnd
         && a.m_pathAfterLastSlash == b.m_pathAfterLastSlash
         && a.m_pathEnd == b.m_pathEnd
-        && a.m_queryEnd == b.m_queryEnd
-        && a.m_fragmentEnd == b.m_fragmentEnd;
+        && a.m_queryEnd == b.m_queryEnd;
 }
 
 bool URLParser::internalValuesConsistent(const URL& url)
@@ -2940,10 +2915,7 @@
         && url.m_portEnd <= url.m_pathAfterLastSlash
         && url.m_pathAfterLastSlash <= url.m_pathEnd
         && url.m_pathEnd <= url.m_queryEnd
-        && url.m_queryEnd <= url.m_fragmentEnd
-        && (url.m_isValid ? url.m_fragmentEnd == url.m_string.length() : !url.m_fragmentEnd);
-    // FIXME: Why do we even store m_fragmentEnd?
-    // It should be able to be deduced from m_isValid and m_string.length() to save memory.
+        && url.m_queryEnd <= url.m_string.length();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to