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

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

Issue 2428093002: [KURL] Avoid re-hashing input if is already canonicalized (Closed)
Patch Set: fix comment typo (trybots prev) 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..168152b9adb9aaae34851e57e7b7c3da6662b9fb 100644
--- a/third_party/WebKit/Source/platform/weborigin/KURL.cpp
+++ b/third_party/WebKit/Source/platform/weborigin/KURL.cpp
@@ -718,10 +718,17 @@ void KURL::init(const KURL& base,
const String& relative,
const WTF::TextEncoding* queryEncoding) {
if (!relative.isNull() && relative.is8Bit()) {
- StringUTF8Adaptor relativeUTF8(relative);
- init(base, relativeUTF8.data(), relativeUTF8.length(), queryEncoding);
- } else
- init(base, relative.characters16(), relative.length(), queryEncoding);
esprehn 2016/10/25 22:23:50 We go down this path when relative.isNull() which
Charlie Harrison 2016/10/27 02:12:36 The null check is just for the is8Bit check which
+ // Avoid using StringUTF8Adaptor because we want the possibly non-ascii data
+ // exposed to init<CHAR> as a String to avoid re-allocation.
+ String utf8 = relative.containsOnlyASCII()
+ ? relative
+ : String::fromUTF8(relative.utf8());
+ init(base, reinterpret_cast<const char*>(utf8.characters8()), utf8.length(),
+ queryEncoding, utf8);
+ } else {
+ init(base, relative.characters16(), relative.length(), queryEncoding,
+ relative);
+ }
initProtocolIsInHTTPFamily();
initInnerURL();
}
@@ -730,7 +737,8 @@ template <typename CHAR>
void KURL::init(const KURL& base,
const CHAR* relative,
int relativeLength,
- const WTF::TextEncoding* queryEncoding) {
+ const WTF::TextEncoding* queryEncoding,
+ const String& originalRelative) {
// 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
@@ -752,9 +760,15 @@ void KURL::init(const KURL& base,
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());
+ // If the canonicalization has not changed the string, avoid re-allocating.
+ // Note: because we are canonicalizing into narrow characters, this check will
+ // always be false for 16 bit inputs.
+ if (output.length() == relativeLength &&
+ !memcmp(output.data(), relative, relativeLength)) {
+ m_string = AtomicString(originalRelative);
+ } else {
+ m_string = AtomicString::fromUTF8(output.data(), output.length());
+ }
}
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