Bug 1264178 - Part 2: Change URL's getter function from PassByReference to ReturnByReference. r=bkelly
authorTom Tung <ttung@mozilla.com>
Mon, 07 Nov 2016 14:59:00 +0800
changeset 351839 3363a134f720f49c2f75cc953a297e5981cfea1f
parent 351838 7245abb243756fdc0b13a09417db08376904620e
child 351840 de39b88af6c226c8cbe2ba0e3e14a8d0dcc7ebe1
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1264178
milestone52.0a1
Bug 1264178 - Part 2: Change URL's getter function from PassByReference to ReturnByReference. r=bkelly
dom/fetch/InternalResponse.h
dom/fetch/Response.h
dom/workers/ServiceWorkerEvents.cpp
--- a/dom/fetch/InternalResponse.h
+++ b/dom/fetch/InternalResponse.h
@@ -80,47 +80,40 @@ public:
     return mType;
   }
 
   bool
   IsError() const
   {
     return Type() == ResponseType::Error;
   }
-
   // GetUrl should return last fetch URL in response's url list and null if
   // response's url list is the empty list.
-  void
-  GetURL(nsCString& aURL) const
+  const nsCString&
+  GetURL() const
   {
     // Empty urlList when response is a synthetic response.
     if (mURLList.IsEmpty()) {
-      aURL.Truncate();
-      return;
+      return EmptyCString();
     }
-
-    aURL.Assign(mURLList.LastElement());
+    return mURLList.LastElement();
   }
-
   void
   GetURLList(nsTArray<nsCString>& aURLList) const
   {
     aURLList.Assign(mURLList);
   }
-
-  void
-  GetUnfilteredURL(nsCString& aURL) const
+  const nsCString&
+  GetUnfilteredURL() const
   {
     if (mWrappedResponse) {
-      return mWrappedResponse->GetURL(aURL);
+      return mWrappedResponse->GetURL();
     }
-
-    return GetURL(aURL);
+    return GetURL();
   }
-
   void
   GetUnfilteredURLList(nsTArray<nsCString>& aURLList) const
   {
     if (mWrappedResponse) {
       return mWrappedResponse->GetURLList(aURLList);
     }
 
     return GetURLList(aURLList);
--- a/dom/fetch/Response.h
+++ b/dom/fetch/Response.h
@@ -43,31 +43,26 @@ public:
     return ResponseBinding::Wrap(aCx, this, aGivenProto);
   }
 
   ResponseType
   Type() const
   {
     return mInternalResponse->Type();
   }
-
   void
   GetUrl(nsAString& aUrl) const
   {
-    nsCString url;
-    mInternalResponse->GetURL(url);
-    CopyUTF8toUTF16(url, aUrl);
+    CopyUTF8toUTF16(mInternalResponse->GetURL(), aUrl);
   }
-
   bool
   Redirected() const
   {
     return mInternalResponse->IsRedirected();
   }
-
   uint16_t
   Status() const
   {
     return mInternalResponse->GetStatus();
   }
 
   bool
   Ok() const
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -232,33 +232,29 @@ public:
 
     nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
     if (obsService) {
       obsService->NotifyObservers(underlyingChannel, "service-worker-synthesized-response", nullptr);
     }
 
     return rv;
   }
-
   bool CSPPermitsResponse(nsILoadInfo* aLoadInfo)
   {
     AssertIsOnMainThread();
     MOZ_ASSERT(aLoadInfo);
-
     nsresult rv;
     nsCOMPtr<nsIURI> uri;
-    nsAutoCString url;
-    mInternalResponse->GetUnfilteredURL(url);
+    nsCString url = mInternalResponse->GetUnfilteredURL();
     if (url.IsEmpty()) {
       // Synthetic response. The buck stops at the worker script.
       url = mScriptSpec;
     }
     rv = NS_NewURI(getter_AddRefs(uri), url, nullptr, nullptr);
     NS_ENSURE_SUCCESS(rv, false);
-
     int16_t decision = nsIContentPolicy::ACCEPT;
     rv = NS_CheckContentLoadPolicy(aLoadInfo->InternalContentPolicyType(), uri,
                                    aLoadInfo->LoadingPrincipal(),
                                    aLoadInfo->LoadingNode(), EmptyCString(),
                                    nullptr, &decision);
     NS_ENSURE_SUCCESS(rv, false);
     return decision == nsIContentPolicy::ACCEPT;
   }
@@ -630,28 +626,26 @@ RespondWithHandler::ResolvedCallback(JSC
       NS_LITERAL_CSTRING("InterceptedUsedResponseWithURL"), mRequestURL);
     return;
   }
 
   RefPtr<InternalResponse> ir = response->GetInternalResponse();
   if (NS_WARN_IF(!ir)) {
     return;
   }
-
   // When an opaque response is encountered, we need the original channel's principal
   // to reflect the final URL. Non-opaque responses are either same-origin or CORS-enabled
   // cross-origin responses, which are treated as same-origin by consumers.
   nsCString responseURL;
   if (response->Type() == ResponseType::Opaque) {
-    ir->GetUnfilteredURL(responseURL);
+    responseURL = ir->GetUnfilteredURL();
     if (NS_WARN_IF(responseURL.IsEmpty())) {
       return;
     }
   }
-
   nsAutoPtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel,
                                                                mRegistration, ir,
                                                                worker->GetChannelInfo(),
                                                                mScriptSpec,
                                                                responseURL,
                                                                mRequestURL,
                                                                mRespondWithScriptSpec,
                                                                mRespondWithLineNumber,