Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1043)

Unified Diff: third_party/WebKit/Source/platform/weborigin/KURL.cpp

Issue 2463703002: Optimize KURL protocols (Closed)
Patch Set: 16 bit test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/weborigin/KURL.cpp
diff --git a/third_party/WebKit/Source/platform/weborigin/KURL.cpp b/third_party/WebKit/Source/platform/weborigin/KURL.cpp
index 72cbe2122c47cf988e8c7ea64f7062690d158836..7f64c97f8a5761bba3985bc16cea0f910beef2bf 100644
--- a/third_party/WebKit/Source/platform/weborigin/KURL.cpp
+++ b/third_party/WebKit/Source/platform/weborigin/KURL.cpp
@@ -240,7 +240,7 @@ KURL::KURL(const AtomicString& canonicalString,
m_protocolIsInHTTPFamily(false),
m_parsed(parsed),
m_string(canonicalString) {
- initProtocolIsInHTTPFamily();
+ initProtocolMetadata();
initInnerURL();
}
@@ -252,6 +252,7 @@ KURL::KURL(WTF::HashTableDeletedValueType)
KURL::KURL(const KURL& other)
: m_isValid(other.m_isValid),
m_protocolIsInHTTPFamily(other.m_protocolIsInHTTPFamily),
+ m_protocol(other.m_protocol),
m_parsed(other.m_parsed),
m_string(other.m_string) {
if (other.m_innerURL.get())
@@ -263,6 +264,7 @@ KURL::~KURL() {}
KURL& KURL::operator=(const KURL& other) {
m_isValid = other.m_isValid;
m_protocolIsInHTTPFamily = other.m_protocolIsInHTTPFamily;
+ m_protocol = other.m_protocol;
m_parsed = other.m_parsed;
m_string = other.m_string;
if (other.m_innerURL)
@@ -276,6 +278,7 @@ KURL KURL::copy() const {
KURL result;
result.m_isValid = m_isValid;
result.m_protocolIsInHTTPFamily = m_protocolIsInHTTPFamily;
+ result.m_protocol = m_protocol.isolatedCopy();
result.m_parsed = m_parsed;
result.m_string = m_string.isolatedCopy();
if (m_innerURL)
@@ -335,7 +338,7 @@ String KURL::lastPathComponent() const {
}
String KURL::protocol() const {
- return componentString(m_parsed.scheme);
+ return m_protocol;
}
String KURL::host() const {
@@ -432,6 +435,7 @@ bool KURL::setProtocol(const String& protocol) {
replacements.SetScheme(charactersOrEmpty(newProtocolUTF8),
url::Component(0, newProtocolUTF8.length()));
replaceComponents(replacements);
+ initProtocolMetadata();
// isValid could be false but we still return true here. This is because
// WebCore or JS scripts can build up a URL by setting individual
@@ -722,7 +726,7 @@ void KURL::init(const KURL& base,
init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding);
} else
init(base, relative.characters16(), relative.length(), queryEncoding);
- initProtocolIsInHTTPFamily();
+ initProtocolMetadata();
initInnerURL();
DCHECK_EQ(protocol(), protocol().lower());
}
@@ -772,50 +776,22 @@ void KURL::initInnerURL() {
m_innerURL.reset();
}
-template <typename CHAR>
-bool internalProtocolIs(const url::Component& scheme,
- const CHAR* spec,
- const char* protocol) {
- const CHAR* begin = spec + scheme.begin;
- const CHAR* end = begin + scheme.len;
-
- while (begin != end && *protocol) {
- ASSERT(toASCIILower(*protocol) == *protocol);
- if (toASCIILower(*begin++) != *protocol++)
- return false;
- }
-
- // Both strings are equal (ignoring case) if and only if all of the characters
- // were equal, and the end of both has been reached.
- return begin == end && !*protocol;
-}
-
-template <typename CHAR>
-bool checkIfProtocolIsInHTTPFamily(const url::Component& scheme,
- const CHAR* spec) {
- if (scheme.len == 4)
- return internalProtocolIs(scheme, spec, "http");
- if (scheme.len == 5)
- return internalProtocolIs(scheme, spec, "https");
- if (scheme.len == 7)
- return internalProtocolIs(scheme, spec, "http-so");
- if (scheme.len == 8)
- return internalProtocolIs(scheme, spec, "https-so");
- return false;
-}
-
-void KURL::initProtocolIsInHTTPFamily() {
+void KURL::initProtocolMetadata() {
if (!m_isValid) {
m_protocolIsInHTTPFamily = false;
return;
}
ASSERT(!m_string.isNull());
- m_protocolIsInHTTPFamily =
- m_string.is8Bit() ? checkIfProtocolIsInHTTPFamily(m_parsed.scheme,
- m_string.characters8())
- : checkIfProtocolIsInHTTPFamily(
- m_parsed.scheme, m_string.characters16());
+ m_protocol = componentString(m_parsed.scheme);
+ if (!m_protocol.isEmpty())
+ m_protocol = (m_protocol);
esprehn 2016/11/04 23:48:32 what does this do? assigning m_protocol to itself
Charlie Harrison 2016/11/04 23:58:35 Oops. That should be m_protocol = AtomicString(m_p
+
+ // TODO(csharrison): Add "http" and "https" to the AtomicString table at init
+ // time so that the normal case here is just a pointer comparison.
+ m_protocolIsInHTTPFamily = m_protocol == "http" || m_protocol == "https" ||
+ m_protocol == "http-so" ||
+ m_protocol == "https-so";
}
bool KURL::protocolIs(const char* protocol) const {
@@ -827,14 +803,9 @@ bool KURL::protocolIs(const char* protocol) const {
// FIXME: Chromium code needs to be fixed for this assert to be enabled.
// ASSERT(strcmp(protocol, "javascript"));
- if (m_string.isNull() || m_parsed.scheme.len <= 0)
+ if (m_string.isNull() || m_protocol.isNull() || m_parsed.scheme.len <= 0)
return *protocol == '\0';
-
- return m_string.is8Bit()
- ? internalProtocolIs(m_parsed.scheme, m_string.characters8(),
- protocol)
- : internalProtocolIs(m_parsed.scheme, m_string.characters16(),
- protocol);
+ return m_protocol == protocol;
}
String KURL::stringForInvalidComponent() const {

Powered by Google App Engine
This is Rietveld 408576698