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

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

Issue 2428093002: [KURL] Avoid re-hashing input if is already canonicalized (Closed)
Patch Set: uh ignore PS 5 I have no idea how that got there :P Created 4 years, 2 months 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
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/KURL.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 666ec1043795a491dc0698c7ab5ff94c498730f4..995f6ba0facc5973ed1be52f9eab74528119e8a6 100644
--- a/third_party/WebKit/Source/platform/weborigin/KURL.cpp
+++ b/third_party/WebKit/Source/platform/weborigin/KURL.cpp
@@ -717,11 +717,29 @@ bool protocolIs(const String& url, const char* protocol) {
void KURL::init(const KURL& base,
const String& relative,
const WTF::TextEncoding* queryEncoding) {
+ url::RawCanonOutputT<char> canonical;
if (!relative.isNull() && relative.is8Bit()) {
StringUTF8Adaptor relativeUTF8(relative);
- init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding);
- } else
- init(base, relative.characters16(), relative.length(), queryEncoding);
+ int relativeLength = static_cast<int>(relativeUTF8.length());
esprehn 2016/10/25 22:23:50 This is scary, our strings can be unsigned in leng
Charlie Harrison 2016/10/27 02:12:36 Done.
+ init(base, relativeUTF8.data(), relativeLength, queryEncoding, &canonical);
+
+ // If the relative input is exactly equal to the canonical output, do not
+ // re-allocate the string. Note that this dangerously makes the input String
+ // an AtomicString, which is not safe for Strings that are meant to be
+ // passed between threads.
+ if (!relative.isEmpty() && relative.containsOnlyASCII() &&
esprehn 2016/10/25 22:23:50 Why does containsOnlyASCII() matter here? I don't
Charlie Harrison 2016/10/27 02:12:36 You're right. removed.
+ relativeLength == canonical.length() &&
+ !memcmp(canonical.data(), relativeUTF8.data(), canonical.length())) {
+ m_string = AtomicString(relative);
+ }
+ } else {
+ init(base, relative.characters16(), relative.length(), queryEncoding,
+ &canonical);
+ }
+
+ if (!m_string)
+ m_string = AtomicString::fromUTF8(canonical.data(), canonical.length());
+
initProtocolIsInHTTPFamily();
initInnerURL();
}
@@ -730,7 +748,8 @@ template <typename CHAR>
void KURL::init(const KURL& base,
const CHAR* relative,
int relativeLength,
- const WTF::TextEncoding* queryEncoding) {
+ const WTF::TextEncoding* queryEncoding,
+ url::RawCanonOutputT<char>* output) {
// As a performance optimization, we do not use the charset converter
// if encoding is UTF-8 or other Unicode encodings. Note that this is
// per HTML5 2.5.3 (resolving URL). The URL canonicalizer will be more
@@ -747,14 +766,9 @@ void KURL::init(const KURL& base,
StringUTF8Adaptor baseUTF8(base.getString());
- url::RawCanonOutputT<char> output;
m_isValid = url::ResolveRelative(baseUTF8.data(), baseUTF8.length(),
base.m_parsed, relative, relativeLength,
- charsetConverter, &output, &m_parsed);
-
- // See FIXME in KURLPrivate in the header. If canonicalization has not
- // changed the string, we can avoid an extra allocation by using assignment.
- m_string = AtomicString::fromUTF8(output.data(), output.length());
+ charsetConverter, output, &m_parsed);
}
void KURL::initInnerURL() {
« no previous file with comments | « third_party/WebKit/Source/platform/weborigin/KURL.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698