<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206076] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206076">206076</a></dd>
<dt>Author</dt> <dd>achristensen@apple.com</dd>
<dt>Date</dt> <dd>2016-09-18 01:01:11 -0700 (Sun, 18 Sep 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformURLcpp">trunk/Source/WebCore/platform/URL.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformURLh">trunk/Source/WebCore/platform/URL.h</a></li>
<li><a href="#trunkSourceWebCoreplatformURLParsercpp">trunk/Source/WebCore/platform/URLParser.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206075 => 206076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-18 05:38:24 UTC (rev 206075)
+++ trunk/Source/WebCore/ChangeLog        2016-09-18 08:01:11 UTC (rev 206076)
</span><span class="lines">@@ -1,3 +1,22 @@
</span><ins>+2016-09-18  Alex Christensen  &lt;achristensen@webkit.org&gt;
+
+        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.
+
</ins><span class="cx"> 2016-09-17  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Inline functions in URLParser
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.cpp (206075 => 206076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.cpp        2016-09-18 05:38:24 UTC (rev 206075)
+++ trunk/Source/WebCore/platform/URL.cpp        2016-09-18 08:01:11 UTC (rev 206076)
</span><span class="lines">@@ -790,18 +790,17 @@
</span><span class="cx"> 
</span><span class="cx"> #ifdef NDEBUG
</span><span class="cx"> 
</span><del>-static inline void assertProtocolIsGood(const char*)
</del><ins>+static inline void assertProtocolIsGood(const char*, size_t)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #else
</span><span class="cx"> 
</span><del>-static void assertProtocolIsGood(const char* protocol)
</del><ins>+static void assertProtocolIsGood(const char* protocol, size_t length)
</ins><span class="cx"> {
</span><del>-    const char* p = protocol;
-    while (*p) {
-        ASSERT(*p &gt; ' ' &amp;&amp; *p &lt; 0x7F &amp;&amp; !(*p &gt;= 'A' &amp;&amp; *p &lt;= 'Z'));
-        ++p;
</del><ins>+    for (size_t i = 0; i &lt; length; ++i) {
+        const char c = protocol[i];
+        ASSERT(c &gt; ' ' &amp;&amp; c &lt; 0x7F &amp;&amp; !(c &gt;= 'A' &amp;&amp; c &lt;= 'Z'));
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -809,7 +808,7 @@
</span><span class="cx"> 
</span><span class="cx"> bool URL::protocolIs(const char* protocol) const
</span><span class="cx"> {
</span><del>-    assertProtocolIsGood(protocol);
</del><ins>+    assertProtocolIsGood(protocol, strlen(protocol));
</ins><span class="cx"> 
</span><span class="cx">     // JavaScript URLs are &quot;valid&quot; and should be executed even if URL decides they are invalid.
</span><span class="cx">     // The free function protocolIsJavaScript() should be used instead. 
</span><span class="lines">@@ -826,6 +825,24 @@
</span><span class="cx">     return !protocol[m_schemeEnd]; // We should have consumed all characters in the argument.
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+bool URL::protocolIs(const LChar* protocol, size_t length) const
+{
+    assertProtocolIsGood(reinterpret_cast&lt;const char*&gt;(protocol), length);
+
+    if (!m_isValid)
+        return false;
+    
+    if (m_schemeEnd != length)
+        return false;
+
+    // Do the comparison without making a new string object.
+    for (unsigned i = 0; i &lt; m_schemeEnd; ++i) {
+        if (!isSchemeCharacterMatchIgnoringCase(m_string[i], protocol[i]))
+            return false;
+    }
+    return true;
+}
+
</ins><span class="cx"> String URL::query() const
</span><span class="cx"> {
</span><span class="cx">     if (m_queryEnd == m_pathEnd)
</span><span class="lines">@@ -1899,7 +1916,7 @@
</span><span class="cx"> 
</span><span class="cx"> static bool protocolIs(StringView stringURL, const char* protocol)
</span><span class="cx"> {
</span><del>-    assertProtocolIsGood(protocol);
</del><ins>+    assertProtocolIsGood(protocol, strlen(protocol));
</ins><span class="cx">     unsigned length = stringURL.length();
</span><span class="cx">     for (unsigned i = 0; i &lt; length; ++i) {
</span><span class="cx">         if (!protocol[i])
</span><span class="lines">@@ -2122,10 +2139,11 @@
</span><span class="cx">     copyASCII(m_string, buffer.data());
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+// FIXME: Why is this different than protocolIs(StringView, const char*)?
</ins><span class="cx"> bool protocolIs(const String&amp; url, const char* protocol)
</span><span class="cx"> {
</span><span class="cx">     // Do the comparison without making a new string object.
</span><del>-    assertProtocolIsGood(protocol);
</del><ins>+    assertProtocolIsGood(protocol, strlen(protocol));
</ins><span class="cx">     bool isLeading = true;
</span><span class="cx">     for (unsigned i = 0, j = 0; url[i]; ++i) {
</span><span class="cx">         // skip leading whitespace and control characters.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformURLh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URL.h (206075 => 206076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URL.h        2016-09-18 05:38:24 UTC (rev 206075)
+++ trunk/Source/WebCore/platform/URL.h        2016-09-18 08:01:11 UTC (rev 206076)
</span><span class="lines">@@ -23,8 +23,7 @@
</span><span class="cx">  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#ifndef URL_h
-#define URL_h
</del><ins>+#pragma once
</ins><span class="cx"> 
</span><span class="cx"> #include &quot;PlatformExportMacros.h&quot;
</span><span class="cx"> #include &lt;wtf/Forward.h&gt;
</span><span class="lines">@@ -130,6 +129,7 @@
</span><span class="cx">     // Returns true if the current URL's protocol is the same as the null-
</span><span class="cx">     // terminated ASCII argument. The argument must be lower-case.
</span><span class="cx">     WEBCORE_EXPORT bool protocolIs(const char*) const;
</span><ins>+    bool protocolIs(const LChar*, size_t) const;
</ins><span class="cx">     bool protocolIsBlob() const { return protocolIs(&quot;blob&quot;); }
</span><span class="cx">     bool protocolIsData() const { return protocolIs(&quot;data&quot;); }
</span><span class="cx">     bool protocolIsInHTTPFamily() const;
</span><span class="lines">@@ -455,5 +455,3 @@
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WTF
</span><del>-
-#endif // URL_h
</del></span></pre></div>
<a id="trunkSourceWebCoreplatformURLParsercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/URLParser.cpp (206075 => 206076)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/URLParser.cpp        2016-09-18 05:38:24 UTC (rev 206075)
+++ trunk/Source/WebCore/platform/URLParser.cpp        2016-09-18 08:01:11 UTC (rev 206076)
</span><span class="lines">@@ -949,9 +949,7 @@
</span><span class="cx">                 m_asciiBuffer.append(':');
</span><span class="cx">                 if (isSpecialScheme(urlScheme)) {
</span><span class="cx">                     m_urlIsSpecial = true;
</span><del>-                    // FIXME: This is unnecessarily allocating a String.
-                    // This should be easy to optimize once https://bugs.webkit.org/show_bug.cgi?id=162035 lands.
-                    if (base.protocol() == urlScheme)
</del><ins>+                    if (base.protocolIs(m_asciiBuffer.data(), m_asciiBuffer.size() - 1))
</ins><span class="cx">                         state = State::SpecialRelativeOrAuthority;
</span><span class="cx">                     else
</span><span class="cx">                         state = State::SpecialAuthoritySlashes;
</span><span class="lines">@@ -1005,7 +1003,7 @@
</span><span class="cx">                 ++c;
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><del>-            if (base.protocol() != &quot;file&quot;) {
</del><ins>+            if (!base.protocolIs(&quot;file&quot;)) {
</ins><span class="cx">                 state = State::Relative;
</span><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="lines">@@ -1442,7 +1440,7 @@
</span><span class="cx">         break;
</span><span class="cx">     case State::File:
</span><span class="cx">         LOG_FINAL_STATE(&quot;File&quot;);
</span><del>-        if (!base.isNull() &amp;&amp; base.protocol() == &quot;file&quot;) {
</del><ins>+        if (!base.isNull() &amp;&amp; base.protocolIs(&quot;file&quot;)) {
</ins><span class="cx">             copyURLPartsUntil(base, URLPart::QueryEnd);
</span><span class="cx">             m_asciiBuffer.append(':');
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>