URL::host should return a StringView to reduce allocations
authorachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2018 20:39:37 +0000 (20:39 +0000)
committerachristensen@apple.com <achristensen@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 25 May 2018 20:39:37 +0000 (20:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185986

Reviewed by Geoff Garen.

Source/WebCore:

No change in behaviour.  Just fewer allocations.

* Modules/plugins/YouTubePluginReplacement.cpp:
(WebCore::isYouTubeURL):
(WebCore::processAndCreateYouTubeURL):
* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::hostName):
(WebCore::WebSocketHandshake::host const):
* contentextensions/ContentExtension.cpp:
(WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::parseAttribute):
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaSessionTitle const):
(WebCore::needsSeekingSupportQuirk):
* html/HTMLPlugInImageElement.cpp:
(WebCore::HTMLPlugInImageElement::restartSimilarPlugIns):
(WebCore::HTMLPlugInImageElement::userDidClickSnapshot):
(WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn):
* html/ImageDocument.cpp:
(WebCore::ImageDocument::finishedParsing):
* html/URLUtils.h:
(WebCore::URLUtils<T>::hostname const):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::setFirstPartyForCookies):
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::loadLink):
* loader/ResourceLoadStatistics.cpp:
(WebCore::ResourceLoadStatistics::primaryDomain):
* loader/mac/LoaderNSURLExtras.mm:
(suggestedFilenameWithMIMEType):
* page/Chrome.cpp:
(WebCore::Chrome::mouseDidMoveOverElement):
* page/Location.cpp:
(WebCore::Location::hostname const):
* page/Page.cpp:
(WebCore::Page::mainFrameLoadStarted):
* page/PerformanceMonitor.cpp:
(WebCore::reportPageOverPostLoadResourceThreshold):
* page/SecurityOrigin.cpp:
(WebCore::isLoopbackIPAddress):
(WebCore::shouldTreatAsPotentiallyTrustworthy):
(WebCore::SecurityOrigin::isLocalHostOrLoopbackIPAddress):
* page/SecurityOrigin.h:
* page/SecurityOriginData.h:
(WebCore::SecurityOriginData::fromURL):
* page/UserContentURLPattern.cpp:
(WebCore::UserContentURLPattern::matchesHost const):
* page/csp/ContentSecurityPolicySource.cpp:
(WebCore::ContentSecurityPolicySource::hostMatches const):
* platform/PublicSuffix.h:
* platform/URL.cpp:
(WebCore::URL::host const):
(WebCore::URL::hostAndPort const):
(WebCore::URL::isMatchingDomain const):
* platform/URL.h:
* platform/mac/SSLKeyGeneratorMac.mm:
(WebCore::signedPublicKeyAndChallengeString):
* platform/network/ResourceRequestBase.h:
(WebCore::registrableDomainsAreEqual):
* platform/network/cf/NetworkStorageSessionCFNet.cpp:
(WebCore::getPartitioningDomain):
* platform/network/cf/SocketStreamHandleImplCFNet.cpp:
(WebCore::SocketStreamHandleImpl::createStreams):
* workers/WorkerLocation.cpp:
(WebCore::WorkerLocation::hostname const):
* workers/service/server/SWServer.cpp:
(WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):

Source/WebKit:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::fetchDiskCacheEntries):
* NetworkProcess/NetworkResourceLoader.cpp:
(WebKit::areFrameAncestorsSameSite):
* NetworkProcess/mac/NetworkProcessMac.mm:
(WebKit::overrideSystemProxies):
* Shared/API/APIURL.h:
(API::URL::host const):
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::addSingleCookie):
(WebKit::WebAutomationSession::deleteAllCookies):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
* WebProcess/Plugins/PluginView.cpp:
(WebKit::PluginView::pluginDidReceiveUserInteraction):
* WebProcess/Plugins/WebPluginInfoProvider.cpp:
(WebKit::WebPluginInfoProvider::populatePluginCache):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::needsHiddenContentEditableQuirk):
(WebKit::needsPlainTextQuirk):
(WebKit::WebPage::determinePrimarySnapshottedPlugIn):

Source/WebKitLegacy:

* WebCoreSupport/WebResourceLoadScheduler.cpp:
(WebResourceLoadScheduler::hostForURL):

Tools:

* TestWebKitAPI/Tests/WebCore/URL.cpp:
(TestWebKitAPI::TEST_F):
* TestWebKitAPI/Tests/WebCore/URLParser.cpp:
(TestWebKitAPI::eq):
* TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm:
(TestWebKitAPI::SSLKeyGeneratorTest::TearDown):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232198 268f45cc-cd09-0410-ab3c-d52691b4dbfc

52 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp
Source/WebCore/Modules/websockets/WebSocketHandshake.cpp
Source/WebCore/contentextensions/ContentExtension.cpp
Source/WebCore/html/HTMLAnchorElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLPlugInImageElement.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/html/URLUtils.h
Source/WebCore/loader/FrameLoader.cpp
Source/WebCore/loader/LinkLoader.cpp
Source/WebCore/loader/ResourceLoadStatistics.cpp
Source/WebCore/loader/mac/LoaderNSURLExtras.mm
Source/WebCore/page/Chrome.cpp
Source/WebCore/page/Location.cpp
Source/WebCore/page/Page.cpp
Source/WebCore/page/PerformanceMonitor.cpp
Source/WebCore/page/SecurityOrigin.cpp
Source/WebCore/page/SecurityOrigin.h
Source/WebCore/page/SecurityOriginData.h
Source/WebCore/page/UserContentURLPattern.cpp
Source/WebCore/page/csp/ContentSecurityPolicySource.cpp
Source/WebCore/platform/PublicSuffix.h
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/URL.h
Source/WebCore/platform/UserAgentQuirks.cpp
Source/WebCore/platform/mac/SSLKeyGeneratorMac.mm
Source/WebCore/platform/network/ResourceRequestBase.h
Source/WebCore/platform/network/cf/NetworkStorageSessionCFNet.cpp
Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp
Source/WebCore/platform/network/curl/CookieJarDB.cpp
Source/WebCore/platform/network/soup/SoupNetworkSession.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/workers/WorkerLocation.cpp
Source/WebCore/workers/service/server/SWServer.cpp
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
Source/WebKit/NetworkProcess/mac/NetworkProcessMac.mm
Source/WebKit/Shared/API/APIURL.h
Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/WebProcess/Plugins/PluginView.cpp
Source/WebKit/WebProcess/Plugins/WebPluginInfoProvider.cpp
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Source/WebKitLegacy/ChangeLog
Source/WebKitLegacy/WebCoreSupport/WebResourceLoadScheduler.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/URL.cpp
Tools/TestWebKitAPI/Tests/WebCore/URLParser.cpp
Tools/TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm

index 6932229..9909f6e 100644 (file)
@@ -1,3 +1,79 @@
+2018-05-25  Alex Christensen  <achristensen@webkit.org>
+
+        URL::host should return a StringView to reduce allocations
+        https://bugs.webkit.org/show_bug.cgi?id=185986
+
+        Reviewed by Geoff Garen.
+
+        No change in behaviour.  Just fewer allocations.
+
+        * Modules/plugins/YouTubePluginReplacement.cpp:
+        (WebCore::isYouTubeURL):
+        (WebCore::processAndCreateYouTubeURL):
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::hostName):
+        (WebCore::WebSocketHandshake::host const):
+        * contentextensions/ContentExtension.cpp:
+        (WebCore::ContentExtensions::ContentExtension::populateConditionCacheIfNeeded):
+        * html/HTMLAnchorElement.cpp:
+        (WebCore::HTMLAnchorElement::parseAttribute):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaSessionTitle const):
+        (WebCore::needsSeekingSupportQuirk):
+        * html/HTMLPlugInImageElement.cpp:
+        (WebCore::HTMLPlugInImageElement::restartSimilarPlugIns):
+        (WebCore::HTMLPlugInImageElement::userDidClickSnapshot):
+        (WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn):
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::finishedParsing):
+        * html/URLUtils.h:
+        (WebCore::URLUtils<T>::hostname const):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::setFirstPartyForCookies):
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::loadLink):
+        * loader/ResourceLoadStatistics.cpp:
+        (WebCore::ResourceLoadStatistics::primaryDomain):
+        * loader/mac/LoaderNSURLExtras.mm:
+        (suggestedFilenameWithMIMEType):
+        * page/Chrome.cpp:
+        (WebCore::Chrome::mouseDidMoveOverElement):
+        * page/Location.cpp:
+        (WebCore::Location::hostname const):
+        * page/Page.cpp:
+        (WebCore::Page::mainFrameLoadStarted):
+        * page/PerformanceMonitor.cpp:
+        (WebCore::reportPageOverPostLoadResourceThreshold):
+        * page/SecurityOrigin.cpp:
+        (WebCore::isLoopbackIPAddress):
+        (WebCore::shouldTreatAsPotentiallyTrustworthy):
+        (WebCore::SecurityOrigin::isLocalHostOrLoopbackIPAddress):
+        * page/SecurityOrigin.h:
+        * page/SecurityOriginData.h:
+        (WebCore::SecurityOriginData::fromURL):
+        * page/UserContentURLPattern.cpp:
+        (WebCore::UserContentURLPattern::matchesHost const):
+        * page/csp/ContentSecurityPolicySource.cpp:
+        (WebCore::ContentSecurityPolicySource::hostMatches const):
+        * platform/PublicSuffix.h:
+        * platform/URL.cpp:
+        (WebCore::URL::host const):
+        (WebCore::URL::hostAndPort const):
+        (WebCore::URL::isMatchingDomain const):
+        * platform/URL.h:
+        * platform/mac/SSLKeyGeneratorMac.mm:
+        (WebCore::signedPublicKeyAndChallengeString):
+        * platform/network/ResourceRequestBase.h:
+        (WebCore::registrableDomainsAreEqual):
+        * platform/network/cf/NetworkStorageSessionCFNet.cpp:
+        (WebCore::getPartitioningDomain):
+        * platform/network/cf/SocketStreamHandleImplCFNet.cpp:
+        (WebCore::SocketStreamHandleImpl::createStreams):
+        * workers/WorkerLocation.cpp:
+        (WebCore::WorkerLocation::hostname const):
+        * workers/service/server/SWServer.cpp:
+        (WebCore::SWServer::performGetOriginsWithRegistrationsCallbacks):
+
 2018-05-24  Dean Jackson  <dino@apple.com>
 
         Need to provide a way to feature detect support for system preview
index c9171dc..5187adf 100644 (file)
@@ -176,7 +176,7 @@ static YouTubePluginReplacement::KeyValueMap queryKeysAndValues(const String& qu
     
 static bool isYouTubeURL(const URL& url)
 {
-    String hostName = url.host();
+    auto hostName = url.host();
     return equalLettersIgnoringASCIICase(hostName, "m.youtube.com")
         || equalLettersIgnoringASCIICase(hostName, "youtu.be")
         || equalLettersIgnoringASCIICase(hostName, "www.youtube.com")
@@ -203,7 +203,7 @@ static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedUR
     if (!isYouTubeURL(url))
         return URL();
 
-    String hostName = url.host();
+    auto hostName = url.host();
     bool isYouTubeMobileWebAppURL = equalLettersIgnoringASCIICase(hostName, "m.youtube.com");
     isYouTubeShortenedURL = equalLettersIgnoringASCIICase(hostName, "youtu.be");
 
index 5455cd1..9f81e06 100644 (file)
@@ -82,7 +82,7 @@ static String hostName(const URL& url, bool secure)
 {
     ASSERT(url.protocolIs("wss") == secure);
     StringBuilder builder;
-    builder.append(url.host().convertToASCIILowercase());
+    builder.append(url.host().toString().convertToASCIILowercase());
     if (url.port() && ((!secure && url.port().value() != 80) || (secure && url.port().value() != 443))) {
         builder.append(':');
         builder.appendNumber(url.port().value());
@@ -146,7 +146,7 @@ void WebSocketHandshake::setURL(const URL& url)
 // FIXME: Return type should just be String, not const String.
 const String WebSocketHandshake::host() const
 {
-    return m_url.host().convertToASCIILowercase();
+    return m_url.host().toString().convertToASCIILowercase();
 }
 
 const String& WebSocketHandshake::clientProtocol() const
index 610e1b8..2b80a2f 100644 (file)
@@ -122,7 +122,7 @@ void ContentExtension::populateConditionCacheIfNeeded(const URL& topURL)
     if (m_cachedTopURL != topURL) {
         DFABytecodeInterpreter interpreter(m_compiledExtension->topURLFiltersBytecode(), m_compiledExtension->topURLFiltersBytecodeLength());
         const uint16_t allLoadTypesAndResourceTypes = LoadTypeMask | ResourceTypeMask;
-        String string = m_compiledExtension->conditionsApplyOnlyToDomain() ? topURL.host() : topURL.string();
+        String string = m_compiledExtension->conditionsApplyOnlyToDomain() ? topURL.host().toString() : topURL.string();
         auto topURLActions = interpreter.interpret(string.utf8(), allLoadTypesAndResourceTypes);
         
         m_cachedTopURLActions.clear();
index 6d25672..aae8b6b 100644 (file)
@@ -244,7 +244,7 @@ void HTMLAnchorElement::parseAttribute(const QualifiedName& name, const AtomicSt
             String parsedURL = stripLeadingAndTrailingHTMLSpaces(value);
             if (document().isDNSPrefetchEnabled() && document().frame()) {
                 if (protocolIsInHTTPFamily(parsedURL) || parsedURL.startsWith("//"))
-                    document().frame()->loader().client().prefetchDNS(document().completeURL(parsedURL).host());
+                    document().frame()->loader().client().prefetchDNS(document().completeURL(parsedURL).host().toString());
             }
         }
         invalidateCachedVisitedLinkHash();
index 25c7df1..a848f95 100644 (file)
@@ -7461,7 +7461,7 @@ String HTMLMediaElement::mediaSessionTitle() const
     if (!title.isEmpty())
         return title;
 
-    title = m_currentSrc.host();
+    title = m_currentSrc.host().toString();
 #if PLATFORM(MAC) || PLATFORM(IOS)
     if (!title.isEmpty())
         title = decodeHostName(title);
@@ -7524,7 +7524,7 @@ static bool needsSeekingSupportQuirk(Document& document)
     if (!document.settings().needsSiteSpecificQuirks())
         return false;
 
-    String host = document.topDocument().url().host();
+    auto host = document.topDocument().url().host();
     return equalLettersIgnoringASCIICase(host, "netflix.com") || host.endsWithIgnoringASCIICase(".netflix.com");
 }
 
index 9a44752..5675eb9 100644 (file)
@@ -435,7 +435,7 @@ void HTMLPlugInImageElement::restartSimilarPlugIns()
     // Restart any other snapshotted plugins in the page with the same origin. Note that they
     // may be in different frames, so traverse from the top of the document.
 
-    String plugInOrigin = m_loadedUrl.host();
+    auto plugInOrigin = m_loadedUrl.host();
     String mimeType = serviceType();
     Vector<Ref<HTMLPlugInImageElement>> similarPlugins;
 
@@ -469,9 +469,9 @@ void HTMLPlugInImageElement::userDidClickSnapshot(MouseEvent& event, bool forwar
     if (forwardEvent)
         m_pendingClickEventFromSnapshot = &event;
 
-    String plugInOrigin = m_loadedUrl.host();
+    auto plugInOrigin = m_loadedUrl.host();
     if (document().page() && !SchemeRegistry::shouldTreatURLSchemeAsLocal(document().page()->mainFrame().document()->baseURL().protocol().toStringWithoutCopying()) && document().page()->settings().autostartOriginPlugInSnapshottingEnabled())
-        document().page()->plugInClient()->didStartFromOrigin(document().page()->mainFrame().document()->baseURL().host(), plugInOrigin, serviceType(), document().page()->sessionID());
+        document().page()->plugInClient()->didStartFromOrigin(document().page()->mainFrame().document()->baseURL().host().toString(), plugInOrigin.toString(), serviceType(), document().page()->sessionID());
 
     LOG(Plugins, "%p User clicked on snapshotted plug-in. Restart.", this);
     restartSnapshottedPlugIn();
@@ -675,7 +675,7 @@ void HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn(const URL& url)
         return;
     }
 
-    if (document().page()->settings().autostartOriginPlugInSnapshottingEnabled() && document().page()->plugInClient() && document().page()->plugInClient()->shouldAutoStartFromOrigin(document().page()->mainFrame().document()->baseURL().host(), url.host(), serviceType())) {
+    if (document().page()->settings().autostartOriginPlugInSnapshottingEnabled() && document().page()->plugInClient() && document().page()->plugInClient()->shouldAutoStartFromOrigin(document().page()->mainFrame().document()->baseURL().host().toString(), url.host().toString(), serviceType())) {
         LOG(Plugins, "%p Plug-in from (%s, %s) is marked to auto-start, set to play", this, document().page()->mainFrame().document()->baseURL().host().utf8().data(), url.host().utf8().data());
         m_snapshotDecision = NeverSnapshot;
         return;
index 85c13ff..a14b2d2 100644 (file)
@@ -168,7 +168,7 @@ void ImageDocument::finishedParsing()
             // back on the hostname if there is no path.
             String name = decodeURLEscapeSequences(url().lastPathComponent());
             if (name.isEmpty())
-                name = url().host();
+                name = url().host().toString();
             setTitle(imageTitle(name, size));
         }
 
index f564a44..a07c081 100644 (file)
@@ -186,7 +186,7 @@ void URLUtils<T>::setHost(const String& value)
 template <typename T>
 String URLUtils<T>::hostname() const
 {
-    return href().host();
+    return href().host().toString();
 }
 
 template <typename T>
index c9db1f4..9b80e95 100644 (file)
@@ -1076,7 +1076,7 @@ void FrameLoader::setFirstPartyForCookies(const URL& url)
     for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame))
         frame->document()->setFirstPartyForCookies(url);
 
-    String registrableDomain = ResourceRequest::partitionName(url.host());
+    String registrableDomain = ResourceRequest::partitionName(url.host().toString());
     for (Frame* frame = &m_frame; frame; frame = frame->tree().traverseNext(&m_frame)) {
         if (SecurityPolicy::shouldInheritSecurityOriginFromOwner(frame->document()->url()) || registrableDomainsAreEqual(frame->document()->url(), registrableDomain))
             frame->document()->setFirstPartyForSameSiteCookies(url);
index 3447776..bcb50d6 100644 (file)
@@ -294,7 +294,7 @@ bool LinkLoader::loadLink(const LinkRelAttribute& relAttribute, const URL& href,
         // FIXME: The href attribute of the link element can be in "//hostname" form, and we shouldn't attempt
         // to complete that as URL <https://bugs.webkit.org/show_bug.cgi?id=48857>.
         if (document.settings().dnsPrefetchingEnabled() && href.isValid() && !href.isEmpty() && document.frame())
-            document.frame()->loader().client().prefetchDNS(href.host());
+            document.frame()->loader().client().prefetchDNS(href.host().toString());
     }
 
     preconnectIfNeeded(relAttribute, href, document, crossOrigin);
index 4df25da..e9c561e 100644 (file)
@@ -333,7 +333,7 @@ void ResourceLoadStatistics::merge(const ResourceLoadStatistics& other)
 
 String ResourceLoadStatistics::primaryDomain(const URL& url)
 {
-    return primaryDomain(url.host());
+    return primaryDomain(url.host().toString());
 }
 
 String ResourceLoadStatistics::primaryDomain(const String& host)
index 9d951cf..11c8ef5 100644 (file)
@@ -48,7 +48,7 @@ NSString *suggestedFilenameWithMIMEType(NSURL *url, const String& mimeType)
 
     if ([filename length] == 0 || [lastPathComponent isEqualToString:@"/"]) {
         // lastPathComponent is no good, try the host.
-        NSString *host = URL(url).host();
+        NSString *host = URL(url).host().toString();
         filename = filenameByFixingIllegalCharacters(host);
         if ([filename length] == 0) {
             // Can't make a filename using this URL, use "unknown".
index e04a90f..770a96b 100644 (file)
@@ -324,7 +324,7 @@ void Chrome::setStatusbarText(Frame& frame, const String& status)
 void Chrome::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags)
 {
     if (result.innerNode() && result.innerNode()->document().isDNSPrefetchEnabled())
-        m_page.mainFrame().loader().client().prefetchDNS(result.absoluteLinkURL().host());
+        m_page.mainFrame().loader().client().prefetchDNS(result.absoluteLinkURL().host().toString());
     m_client.mouseDidMoveOverElement(result, modifierFlags);
 
     InspectorInstrumentation::mouseDidMoveOverElement(m_page, result, modifierFlags);
index ccf8f4b..7b98a06 100644 (file)
@@ -94,7 +94,7 @@ String Location::hostname() const
     if (!m_frame)
         return String();
 
-    return url().host();
+    return url().host().toString();
 }
 
 String Location::port() const
index 271f416..a3d874d 100644 (file)
@@ -2104,7 +2104,7 @@ void Page::mainFrameLoadStarted(const URL& destinationURL, FrameLoadType type)
 {
     String domain;
 #if ENABLE(PUBLIC_SUFFIX_LIST)
-    domain = topPrivatelyControlledDomain(destinationURL.host());
+    domain = topPrivatelyControlledDomain(destinationURL.host().toString());
 #else
     UNUSED_PARAM(destinationURL);
 #endif
index aaa7d5c..f1021fa 100644 (file)
@@ -148,7 +148,7 @@ static void reportPageOverPostLoadResourceThreshold(Page& page, ReportingReason
     if (!document)
         return;
 
-    String domain = topPrivatelyControlledDomain(document->url().host());
+    String domain = topPrivatelyControlledDomain(document->url().host().toString());
     if (domain.isEmpty())
         return;
 
index 9113ee6..8107330 100644 (file)
@@ -99,7 +99,7 @@ static bool shouldTreatAsUniqueOrigin(const URL& url)
     return false;
 }
 
-static bool isLoopbackIPAddress(const String& host)
+static bool isLoopbackIPAddress(StringView host)
 {
     // The IPv6 loopback address is 0:0:0:0:0:0:0:1, which compresses to ::1.
     if (host == "[::1]")
@@ -137,7 +137,7 @@ static bool shouldTreatAsPotentiallyTrustworthy(const String& protocol, const St
 
 bool shouldTreatAsPotentiallyTrustworthy(const URL& url)
 {
-    return shouldTreatAsPotentiallyTrustworthy(url.protocol().toStringWithoutCopying(), url.host());
+    return shouldTreatAsPotentiallyTrustworthy(url.protocol().toStringWithoutCopying(), url.host().toStringWithoutCopying());
 }
 
 SecurityOrigin::SecurityOrigin(const URL& url)
@@ -548,7 +548,7 @@ bool SecurityOrigin::isSameSchemeHostPort(const SecurityOrigin& other) const
     return true;
 }
 
-bool SecurityOrigin::isLocalHostOrLoopbackIPAddress(const String& host)
+bool SecurityOrigin::isLocalHostOrLoopbackIPAddress(StringView host)
 {
     if (isLoopbackIPAddress(host))
         return true;
index 9b72d66..5adf501 100644 (file)
@@ -202,7 +202,7 @@ public:
 
     bool isPotentiallyTrustworthy() const { return m_isPotentiallyTrustworthy; }
 
-    static bool isLocalHostOrLoopbackIPAddress(const String& host);
+    static bool isLocalHostOrLoopbackIPAddress(StringView);
 
     const SecurityOriginData& data() const { return m_data; }
 
index 7990239..69c21b6 100644 (file)
@@ -50,7 +50,7 @@ struct SecurityOriginData {
     {
         return SecurityOriginData {
             url.protocol().isNull() ? emptyString() : url.protocol().toString().convertToASCIILowercase(),
-            url.host().isNull() ? emptyString() : url.host().convertToASCIILowercase(),
+            url.host().isNull() ? emptyString() : url.host().toString().convertToASCIILowercase(),
             url.port()
         };
     }
index e1fdc9b..b9b8115 100644 (file)
@@ -125,7 +125,7 @@ bool UserContentURLPattern::matches(const URL& test) const
 
 bool UserContentURLPattern::matchesHost(const URL& test) const
 {
-    const String& host = test.host();
+    auto host = test.host();
     if (equalIgnoringASCIICase(host, m_host))
         return true;
 
index bcac664..04d7e99 100644 (file)
@@ -64,8 +64,8 @@ bool ContentSecurityPolicySource::schemeMatches(const URL& url) const
 
 bool ContentSecurityPolicySource::hostMatches(const URL& url) const
 {
-    const String& host = url.host();
-    return equalIgnoringASCIICase(host, m_host) || (m_hostHasWildcard && host.endsWithIgnoringASCIICase("." + m_host));
+    auto host = url.host();
+    return equalIgnoringASCIICase(host, m_host) || (m_hostHasWildcard && host.endsWithIgnoringASCIICase(makeString(".", m_host)));
 
 }
 
index 22a539a..a0e0e4d 100644 (file)
@@ -23,8 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef PublicSuffix_h
-#define PublicSuffix_h
+#pragma once
 
 #include <wtf/text/WTFString.h>
 
@@ -39,5 +38,3 @@ String decodeHostName(const String& domain);
 } // namespace WebCore
 
 #endif // ENABLE(PUBLIC_SUFFIX_LIST)
-
-#endif // PublicSuffix_h
index 9900e55..18e5959 100644 (file)
@@ -155,10 +155,10 @@ StringView URL::protocol() const
     return StringView(m_string).substring(0, m_schemeEnd);
 }
 
-String URL::host() const
+StringView URL::host() const
 {
     unsigned start = hostStart();
-    return m_string.substring(start, m_hostEnd - start);
+    return StringView(m_string).substring(start, m_hostEnd - start);
 }
 
 std::optional<uint16_t> URL::port() const
@@ -180,8 +180,8 @@ std::optional<uint16_t> URL::port() const
 String URL::hostAndPort() const
 {
     if (auto port = this->port())
-        return host() + ':' + String::number(port.value());
-    return host();
+        return makeString(host(), ':', String::number(port.value()));
+    return host().toString();
 }
 
 String URL::protocolHostAndPort() const
@@ -796,7 +796,7 @@ bool URL::isMatchingDomain(const String& domain) const
     if (!host.endsWith(domain))
         return false;
 
-    return host.length() == domain.length() || host.characterAt(host.length() - domain.length() - 1) == '.';
+    return host.length() == domain.length() || host[host.length() - domain.length() - 1] == '.';
 }
 
 String encodeWithURLEscapeSequences(const String& input)
index 1c05d99..d9a02a6 100644 (file)
@@ -104,7 +104,7 @@ public:
     WEBCORE_EXPORT String stringCenterEllipsizedToLength(unsigned length = 1024) const;
 
     WEBCORE_EXPORT StringView protocol() const;
-    WEBCORE_EXPORT String host() const;
+    WEBCORE_EXPORT StringView host() const;
     WEBCORE_EXPORT std::optional<uint16_t> port() const;
     WEBCORE_EXPORT String hostAndPort() const;
     WEBCORE_EXPORT String protocolHostAndPort() const;
index 947c83a..578c450 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 
 static bool isGoogle(const URL& url)
 {
-    String baseDomain = topPrivatelyControlledDomain(url.host());
+    String baseDomain = topPrivatelyControlledDomain(url.host().toString());
 
     // Our Google UA is *very* complicated to get right. Read
     // https://webkit.org/b/142074 carefully before changing. Test that Earth
@@ -60,7 +60,7 @@ static bool isGoogle(const URL& url)
 // that works in Chrome that WebKit cannot handle. Prefer other quirks instead.
 static bool urlRequiresChromeBrowser(const URL& url)
 {
-    String baseDomain = topPrivatelyControlledDomain(url.host());
+    String baseDomain = topPrivatelyControlledDomain(url.host().toString());
 
     // Needed for fonts on many sites to work with WebKit.
     // https://bugs.webkit.org/show_bug.cgi?id=147296
@@ -78,7 +78,7 @@ static bool urlRequiresChromeBrowser(const URL& url)
 
 static bool urlRequiresMacintoshPlatform(const URL& url)
 {
-    String domain = url.host();
+    String domain = url.host().toString();
     String baseDomain = topPrivatelyControlledDomain(domain);
 
     // At least finance.yahoo.com displays a mobile version with WebKitGTK+'s standard user agent.
index 4760e79..4700b01 100644 (file)
@@ -246,7 +246,7 @@ String signedPublicKeyAndChallengeString(unsigned keySizeIndex, const String& ch
 
     auto challenge = challengeString.isAllASCII() ? challengeString.ascii() : "";
 
-    return signedPublicKeyAndChallengeString(keySize, challenge, keygenKeychainItemName(url.host()));
+    return signedPublicKeyAndChallengeString(keySize, challenge, keygenKeychainItemName(url.host().toString()));
 }
 
 }
index 29b5572..7536009 100644 (file)
@@ -255,11 +255,11 @@ bool equalIgnoringHeaderFields(const ResourceRequestBase&, const ResourceRequest
 // FIXME: Find a better place for these functions.
 inline bool registrableDomainsAreEqual(const URL& a, const URL& b)
 {
-    return ResourceRequestBase::partitionName(a.host()) == ResourceRequestBase::partitionName(b.host());
+    return ResourceRequestBase::partitionName(a.host().toString()) == ResourceRequestBase::partitionName(b.host().toString());
 }
 inline bool registrableDomainsAreEqual(const URL& a, const String& registrableDomain)
 {
-    return ResourceRequestBase::partitionName(a.host()) == registrableDomain;
+    return ResourceRequestBase::partitionName(a.host().toString()) == registrableDomain;
 }
 
 inline bool operator==(const ResourceRequest& a, const ResourceRequest& b) { return ResourceRequestBase::equal(a, b); }
index 2eb601c..5fab809 100644 (file)
@@ -198,11 +198,11 @@ String NetworkStorageSession::cookieStoragePartition(const ResourceRequest& requ
 static inline String getPartitioningDomain(const URL& url) 
 {
 #if ENABLE(PUBLIC_SUFFIX_LIST)
-    auto domain = topPrivatelyControlledDomain(url.host());
+    auto domain = topPrivatelyControlledDomain(url.host().toString());
     if (domain.isEmpty())
-        domain = url.host();
+        domain = url.host().toString();
 #else
-    auto domain = url.host();
+    auto domain = url.host().toString();
 #endif
     return domain;
 }
index 9ed5aa0..04983a6 100644 (file)
@@ -312,7 +312,7 @@ void SocketStreamHandleImpl::createStreams()
     if (m_connectionType == Unknown)
         return;
 
-    RetainPtr<CFStringRef> host = m_url.host().createCFString();
+    RetainPtr<CFStringRef> host = m_url.host().toString().createCFString();
 
     // Creating streams to final destination, not to proxy.
     CFReadStreamRef readStream = 0;
index ee52b50..13f15fc 100644 (file)
@@ -245,7 +245,7 @@ bool CookieJarDB::searchCookies(const String& requestUrl, const std::optional<bo
         return false;
 
     URL requestUrlObj(ParsedURLString, requestUrl);
-    String requestHost(requestUrlObj.host().convertToASCIILowercase());
+    String requestHost(requestUrlObj.host().toString().convertToASCIILowercase());
     String requestPath(requestUrlObj.path().convertToASCIILowercase());
 
     if (requestHost.isEmpty())
@@ -382,7 +382,7 @@ int CookieJarDB::setCookie(const String& url, const String& cookie, bool fromJav
         return -1;
 
     URL urlObj(ParsedURLString, url);
-    String host(urlObj.host());
+    String host(urlObj.host().toString());
     String path(urlObj.path());
 
     Cookie cookieObj;
@@ -417,7 +417,7 @@ int CookieJarDB::deleteCookie(const String& url, const String& name)
 
     URL urlObj(ParsedURLString, urlCopied);
     if (urlObj.isValid()) {
-        String hostStr(urlObj.host());
+        String hostStr(urlObj.host().toString());
         String pathStr(urlObj.path());
         int ret = deleteCookieInternal(name, hostStr, pathStr);
         ASSERT(checkSQLiteReturnCode(ret, SQLITE_DONE));
index 0b39f28..2c29a51 100644 (file)
@@ -277,7 +277,7 @@ std::optional<ResourceError> SoupNetworkSession::checkTLSErrors(const URL& reque
     if (!tlsErrors)
         return std::nullopt;
 
-    auto it = clientCertificates().find(requestURL.host());
+    auto it = clientCertificates().find(requestURL.host().toString());
     if (it != clientCertificates().end() && it->value.contains(certificate))
         return std::nullopt;
 
index a2e29fa..0c5e173 100644 (file)
@@ -369,7 +369,7 @@ static bool writeURL(WCDataObject *data, const URL& url, String title, bool with
     if (title.isEmpty()) {
         title = url.lastPathComponent();
         if (title.isEmpty())
-            title = url.host();
+            title = url.host().toString();
     }
 
     STGMEDIUM medium = {0};
@@ -707,7 +707,7 @@ void Pasteboard::write(const PasteboardURL& pasteboardURL)
     if (title.isEmpty()) {
         title = pasteboardURL.url.lastPathComponent();
         if (title.isEmpty())
-            title = pasteboardURL.url.host();
+            title = pasteboardURL.url.host().toString();
     }
 
     // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title
index 598f50c..7c1dc93 100644 (file)
@@ -48,7 +48,7 @@ String WorkerLocation::host() const
 
 String WorkerLocation::hostname() const
 {
-    return m_url.host();
+    return m_url.host().toString();
 }
 
 String WorkerLocation::port() const
index 1521bf3..dc325dd 100644 (file)
@@ -866,7 +866,7 @@ void SWServer::performGetOriginsWithRegistrationsCallbacks()
     HashSet<SecurityOriginData> originsWithRegistrations;
     for (auto& key : m_registrations.keys()) {
         originsWithRegistrations.add(key.topOrigin());
-        originsWithRegistrations.add(SecurityOriginData { key.scope().protocol().toString(), key.scope().host(), key.scope().port() });
+        originsWithRegistrations.add(SecurityOriginData { key.scope().protocol().toString(), key.scope().host().toString(), key.scope().port() });
     }
 
     auto callbacks = WTFMove(m_getOriginsWithRegistrationsCallbacks);
index 433aadd..893b761 100644 (file)
@@ -1,3 +1,32 @@
+2018-05-25  Alex Christensen  <achristensen@webkit.org>
+
+        URL::host should return a StringView to reduce allocations
+        https://bugs.webkit.org/show_bug.cgi?id=185986
+
+        Reviewed by Geoff Garen.
+
+        * NetworkProcess/NetworkProcess.cpp:
+        (WebKit::fetchDiskCacheEntries):
+        * NetworkProcess/NetworkResourceLoader.cpp:
+        (WebKit::areFrameAncestorsSameSite):
+        * NetworkProcess/mac/NetworkProcessMac.mm:
+        (WebKit::overrideSystemProxies):
+        * Shared/API/APIURL.h:
+        (API::URL::host const):
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::addSingleCookie):
+        (WebKit::WebAutomationSession::deleteAllCookies):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::processDidTerminateOrFailedToLaunch):
+        * WebProcess/Plugins/PluginView.cpp:
+        (WebKit::PluginView::pluginDidReceiveUserInteraction):
+        * WebProcess/Plugins/WebPluginInfoProvider.cpp:
+        (WebKit::WebPluginInfoProvider::populatePluginCache):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::needsHiddenContentEditableQuirk):
+        (WebKit::needsPlainTextQuirk):
+        (WebKit::WebPage::determinePrimarySnapshottedPlugIn):
+
 2018-05-25  Adrian Perez de Castro  <aperez@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.21.2 release.
index a4bc45e..3afeaab 100644 (file)
@@ -477,7 +477,7 @@ static void fetchDiskCacheEntries(PAL::SessionID sessionID, OptionSet<WebsiteDat
             }
 
             auto url = traversalEntry->entry.response().url();
-            auto result = originsAndSizes.add({url.protocol().toString(), url.host(), url.port()}, 0);
+            auto result = originsAndSizes.add({url.protocol().toString(), url.host().toString(), url.port()}, 0);
 
             if (fetchOptions.contains(WebsiteDataFetchOption::ComputeSizes))
                 result.iterator->value += traversalEntry->entry.sourceStorageRecord().header.size() + traversalEntry->recordInfo.bodySize;
index 240f4a2..e64e7ff 100644 (file)
@@ -364,7 +364,7 @@ void NetworkResourceLoader::abort()
 static bool areFrameAncestorsSameSite(const ResourceResponse& response, const Vector<RefPtr<SecurityOrigin>>& frameAncestorOrigins)
 {
 #if ENABLE(PUBLIC_SUFFIX_LIST)
-    auto responsePartition = ResourceRequest::partitionName(response.url().host());
+    auto responsePartition = ResourceRequest::partitionName(response.url().host().toString());
     return frameAncestorOrigins.findMatching([&](const auto& item) {
         return item->isUnique() || ResourceRequest::partitionName(item->host()) != responsePartition;
     }) == notFound;
index b99fa52..9281590 100644 (file)
@@ -72,7 +72,7 @@ static void overrideSystemProxies(const String& httpProxy, const String& httpsPr
     if (!httpProxy.isNull()) {
         URL httpProxyURL(URL(), httpProxy);
         if (httpProxyURL.isValid()) {
-            [proxySettings setObject:nsStringFromWebCoreString(httpProxyURL.host()) forKey:(NSString *)kCFNetworkProxiesHTTPProxy];
+            [proxySettings setObject:nsStringFromWebCoreString(httpProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPProxy];
             if (httpProxyURL.port()) {
                 NSNumber *port = [NSNumber numberWithInt:httpProxyURL.port().value()];
                 [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPPort];
@@ -86,7 +86,7 @@ static void overrideSystemProxies(const String& httpProxy, const String& httpsPr
         URL httpsProxyURL(URL(), httpsProxy);
         if (httpsProxyURL.isValid()) {
 #if !ENABLE(MINIMAL_SIMULATOR)
-            [proxySettings setObject:nsStringFromWebCoreString(httpsProxyURL.host()) forKey:(NSString *)kCFNetworkProxiesHTTPSProxy];
+            [proxySettings setObject:nsStringFromWebCoreString(httpsProxyURL.host().toString()) forKey:(NSString *)kCFNetworkProxiesHTTPSProxy];
             if (httpsProxyURL.port()) {
                 NSNumber *port = [NSNumber numberWithInt:httpsProxyURL.port().value()];
                 [proxySettings setObject:port forKey:(NSString *)kCFNetworkProxiesHTTPSPort];
index 7e0fae1..7b01d0e 100644 (file)
@@ -64,7 +64,7 @@ public:
     WTF::String host() const
     {
         parseURLIfNecessary();
-        return m_parsedURL->isValid() ? m_parsedURL->host() : WTF::String();
+        return m_parsedURL->isValid() ? m_parsedURL->host().toString() : WTF::String();
     }
 
     WTF::String protocol() const
index 455fa42..149d02c 100644 (file)
@@ -1317,7 +1317,7 @@ void WebAutomationSession::addSingleCookie(const String& browsingContextHandle,
 
     // Inherit the domain/host from the main frame's URL if it is not explicitly set.
     if (domain.isEmpty())
-        domain = activeURL.host();
+        domain = activeURL.host().toString();
 
     cookie.domain = domainByAddingDotPrefixIfNeeded(domain);
 
@@ -1361,7 +1361,7 @@ void WebAutomationSession::deleteAllCookies(ErrorString& errorString, const Stri
     ASSERT(activeURL.isValid());
 
     WebCookieManagerProxy* cookieManager = m_processPool->supplement<WebCookieManagerProxy>();
-    cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), domainByAddingDotPrefixIfNeeded(activeURL.host()));
+    cookieManager->deleteCookiesForHostname(page->websiteDataStore().sessionID(), domainByAddingDotPrefixIfNeeded(activeURL.host().toString()));
 }
 
 void WebAutomationSession::getSessionPermissions(ErrorString&, RefPtr<JSON::ArrayOf<Inspector::Protocol::Automation::SessionPermissionData>>& out_permissions)
index cbb2719..ea43629 100644 (file)
@@ -5799,7 +5799,7 @@ void WebPageProxy::processDidTerminate(ProcessTerminationReason reason)
 
 #if PLATFORM(IOS)
     if (m_process->isUnderMemoryPressure()) {
-        String domain = WebCore::topPrivatelyControlledDomain(WebCore::URL(WebCore::ParsedURLString, currentURL()).host());
+        String domain = WebCore::topPrivatelyControlledDomain(WebCore::URL(WebCore::ParsedURLString, currentURL()).host().toString());
         if (!domain.isEmpty())
             logDiagnosticMessageWithEnhancedPrivacy(WebCore::DiagnosticLoggingKeys::domainCausingJetsamKey(), domain, WebCore::ShouldSample::No);
     }
index 50dd41e..77d63b2 100644 (file)
@@ -676,7 +676,7 @@ void WebProcessProxy::processDidTerminateOrFailedToLaunch()
 #if ENABLE(PUBLIC_SUFFIX_LIST)
     if (pages.size() == 1) {
         auto& page = *pages[0];
-        String domain = topPrivatelyControlledDomain(WebCore::URL(WebCore::ParsedURLString, page.currentURL()).host());
+        String domain = topPrivatelyControlledDomain(WebCore::URL(WebCore::ParsedURLString, page.currentURL()).host().toString());
         if (!domain.isEmpty())
             page.logDiagnosticMessageWithEnhancedPrivacy(WebCore::DiagnosticLoggingKeys::domainCausingCrashKey(), domain, WebCore::ShouldSample::No);
     }
index bcfee00..90e0109 100644 (file)
@@ -1831,8 +1831,8 @@ void PluginView::pluginDidReceiveUserInteraction()
     m_didReceiveUserInteraction = true;
 
     HTMLPlugInImageElement& plugInImageElement = downcast<HTMLPlugInImageElement>(*m_pluginElement);
-    String pageOrigin = plugInImageElement.document().page()->mainFrame().document()->baseURL().host();
-    String pluginOrigin = plugInImageElement.loadedUrl().host();
+    String pageOrigin = plugInImageElement.document().page()->mainFrame().document()->baseURL().host().toString();
+    String pluginOrigin = plugInImageElement.loadedUrl().host().toString();
     String mimeType = plugInImageElement.serviceType();
 
     WebProcess::singleton().plugInDidReceiveUserInteraction(pageOrigin, pluginOrigin, mimeType, plugInImageElement.document().page()->sessionID());
index 347f588..4bd1db6 100644 (file)
@@ -156,7 +156,7 @@ void WebPluginInfoProvider::populatePluginCache(const WebCore::Page& page)
     }
 
 #if PLATFORM(MAC)
-    String pageHost = page.mainFrame().loader().documentLoader()->responseURL().host();
+    String pageHost = page.mainFrame().loader().documentLoader()->responseURL().host().toString();
     if (pageHost.isNull())
         return;
     for (auto& info : m_cachedPlugins) {
index c1a313e..e7b2dda 100644 (file)
@@ -4848,9 +4848,7 @@ static bool needsHiddenContentEditableQuirk(bool needsQuirks, const URL& url)
     if (!needsQuirks)
         return false;
 
-    String host = url.host();
-    String path = url.path();
-    return equalLettersIgnoringASCIICase(host, "docs.google.com");
+    return equalLettersIgnoringASCIICase(url.host(), "docs.google.com");
 }
 
 static bool needsPlainTextQuirk(bool needsQuirks, const URL& url)
@@ -4858,7 +4856,7 @@ static bool needsPlainTextQuirk(bool needsQuirks, const URL& url)
     if (!needsQuirks)
         return false;
 
-    String host = url.host();
+    auto host = url.host();
 
     if (equalLettersIgnoringASCIICase(host, "twitter.com"))
         return true;
@@ -5431,8 +5429,8 @@ void WebPage::determinePrimarySnapshottedPlugIn()
 
     LOG(Plugins, "Primary Plug-In Detection: success - found a candidate plug-in - inform it.");
     m_didFindPrimarySnapshottedPlugin = true;
-    m_primaryPlugInPageOrigin = m_page->mainFrame().document()->baseURL().host();
-    m_primaryPlugInOrigin = candidatePlugIn->loadedUrl().host();
+    m_primaryPlugInPageOrigin = m_page->mainFrame().document()->baseURL().host().toString();
+    m_primaryPlugInOrigin = candidatePlugIn->loadedUrl().host().toString();
     m_primaryPlugInMimeType = candidatePlugIn->serviceType();
 
     candidatePlugIn->setIsPrimarySnapshottedPlugIn(true);
index c2ba26d..a5ba29c 100644 (file)
@@ -1,3 +1,13 @@
+2018-05-25  Alex Christensen  <achristensen@webkit.org>
+
+        URL::host should return a StringView to reduce allocations
+        https://bugs.webkit.org/show_bug.cgi?id=185986
+
+        Reviewed by Geoff Garen.
+
+        * WebCoreSupport/WebResourceLoadScheduler.cpp:
+        (WebResourceLoadScheduler::hostForURL):
+
 2018-05-11  Charles Vazac  <cvazac@gmail.com>
 
         Runtime feature flag for Server-Timing
index 641e67c..34542df 100644 (file)
@@ -66,7 +66,7 @@ WebResourceLoadScheduler::HostInformation* WebResourceLoadScheduler::hostForURL(
         return m_nonHTTPProtocolHost;
 
     m_hosts.checkConsistency();
-    String hostName = url.host();
+    String hostName = url.host().toString();
     HostInformation* host = m_hosts.get(hostName);
     if (!host && createHostPolicy == CreateIfNotFound) {
         host = new HostInformation(hostName, maxRequestsInFlightPerHost);
index de863a4..4e60374 100644 (file)
@@ -1,3 +1,17 @@
+2018-05-25  Alex Christensen  <achristensen@webkit.org>
+
+        URL::host should return a StringView to reduce allocations
+        https://bugs.webkit.org/show_bug.cgi?id=185986
+
+        Reviewed by Geoff Garen.
+
+        * TestWebKitAPI/Tests/WebCore/URL.cpp:
+        (TestWebKitAPI::TEST_F):
+        * TestWebKitAPI/Tests/WebCore/URLParser.cpp:
+        (TestWebKitAPI::eq):
+        * TestWebKitAPI/Tests/mac/SSLKeyGenerator.mm:
+        (TestWebKitAPI::SSLKeyGeneratorTest::TearDown):
+
 2018-05-25  Ms2ger  <Ms2ger@igalia.com>
 
         Minor improvements to wpt exporter.
index 888a742..9688cdb 100644 (file)
@@ -59,7 +59,7 @@ TEST_F(URLTest, URLConstructorConstChar)
     EXPECT_TRUE(kurl.isValid());
 
     EXPECT_EQ(kurl.protocol() == "http", true);
-    EXPECT_EQ(String("www.example.com"), kurl.host());
+    EXPECT_EQ(String("www.example.com"), kurl.host().toString());
     EXPECT_TRUE(!!kurl.port());
     EXPECT_EQ(8080, kurl.port().value());
     EXPECT_EQ(String("username"), kurl.user());
index f3bdea7..0514dcf 100644 (file)
@@ -64,7 +64,8 @@ struct ExpectedParts {
     }
 };
 
-static bool eq(const String& s1, const String& s2)
+template<typename T, typename U>
+bool eq(T&& s1, U&& s2)
 {
     EXPECT_STREQ(s1.utf8().data(), s2.utf8().data());
     return s1.utf8() == s2.utf8();
@@ -90,7 +91,7 @@ static void checkURL(const String& urlString, const ExpectedParts& parts, TestTa
 {
     auto url = URL(URL(), urlString);
     
-    EXPECT_TRUE(eq(parts.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(parts.protocol, url.protocol()));
     EXPECT_TRUE(eq(parts.user, url.user()));
     EXPECT_TRUE(eq(parts.password, url.pass()));
     EXPECT_TRUE(eq(parts.host, url.host()));
@@ -117,7 +118,7 @@ static void checkRelativeURL(const String& urlString, const String& baseURLStrin
 {
     auto url = URL(URL(URL(), baseURLString), urlString);
     
-    EXPECT_TRUE(eq(parts.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(parts.protocol, url.protocol()));
     EXPECT_TRUE(eq(parts.user, url.user()));
     EXPECT_TRUE(eq(parts.password, url.pass()));
     EXPECT_TRUE(eq(parts.host, url.host()));
@@ -146,7 +147,7 @@ static void checkURLDifferences(const String& urlString, const ExpectedParts& pa
     UNUSED_PARAM(partsOld); // FIXME: Remove all the old expected parts.
     auto url = URL(URL(), urlString);
     
-    EXPECT_TRUE(eq(partsNew.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(partsNew.protocol, url.protocol()));
     EXPECT_TRUE(eq(partsNew.user, url.user()));
     EXPECT_TRUE(eq(partsNew.password, url.pass()));
     EXPECT_TRUE(eq(partsNew.host, url.host()));
@@ -175,7 +176,7 @@ static void checkRelativeURLDifferences(const String& urlString, const String& b
     UNUSED_PARAM(partsOld); // FIXME: Remove all the old expected parts.
     auto url = URL(URL(URL(), baseURLString), urlString);
     
-    EXPECT_TRUE(eq(partsNew.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(partsNew.protocol, url.protocol()));
     EXPECT_TRUE(eq(partsNew.user, url.user()));
     EXPECT_TRUE(eq(partsNew.password, url.pass()));
     EXPECT_TRUE(eq(partsNew.host, url.host()));
@@ -213,7 +214,7 @@ static void checkURL(const String& urlString, const TextEncoding& encoding, cons
 {
     URLParser parser(urlString, { }, encoding);
     auto url = parser.result();
-    EXPECT_TRUE(eq(parts.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(parts.protocol, url.protocol()));
     EXPECT_TRUE(eq(parts.user, url.user()));
     EXPECT_TRUE(eq(parts.password, url.pass()));
     EXPECT_TRUE(eq(parts.host, url.host()));
@@ -239,7 +240,7 @@ static void checkURL(const String& urlString, const String& baseURLString, const
     URLParser baseParser(baseURLString, { }, encoding);
     URLParser parser(urlString, baseParser.result(), encoding);
     auto url = parser.result();
-    EXPECT_TRUE(eq(parts.protocol, url.protocol().toString()));
+    EXPECT_TRUE(eq(parts.protocol, url.protocol()));
     EXPECT_TRUE(eq(parts.user, url.user()));
     EXPECT_TRUE(eq(parts.password, url.pass()));
     EXPECT_TRUE(eq(parts.host, url.host()));
index d8c748c..dde8c7d 100644 (file)
@@ -83,12 +83,12 @@ public:
         SecItemDelete((__bridge CFDictionaryRef) @{
             (id)kSecClass: (id)kSecClassKey,
             (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate,
-            (id)kSecAttrLabel: WebCore::keygenKeychainItemName(url.host()),
+            (id)kSecAttrLabel: WebCore::keygenKeychainItemName(url.host().toString()),
         });
         SecItemDelete((__bridge CFDictionaryRef) @{
             (id)kSecClass: (id)kSecClassKey,
             (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPublic,
-            (id)kSecAttrLabel: WebCore::keygenKeychainItemName(url.host()),
+            (id)kSecAttrLabel: WebCore::keygenKeychainItemName(url.host().toString()),
         });
     }
 };