Chromium Code Reviews| 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() { |