Bug 1153258 - directly instantiate nsStandardURL in nsChromeProtocolHandler.cpp; r=bsmedberg
authorNathan Froyd <froydnj@mozilla.com>
Thu, 02 Apr 2015 10:12:27 -0400
changeset 268741 c15940fac6d73a9f8958b3ba4f8b6e5798ee38bb
parent 268740 a872ba7db8a40b81c3d29b95fd8e15de80e957c7
child 268742 eee4e1faf74547f2b6945bd5d7004d81f5807632
push id4830
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:18:48 +0000
treeherdermozilla-beta@4c2175bb0420 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1153258
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1153258 - directly instantiate nsStandardURL in nsChromeProtocolHandler.cpp; r=bsmedberg Knowing how to instantiate nsStandardURL directly enables us to avoid several extraneous reference counting and QueryInterface operations.
chrome/nsChromeProtocolHandler.cpp
--- a/chrome/nsChromeProtocolHandler.cpp
+++ b/chrome/nsChromeProtocolHandler.cpp
@@ -19,16 +19,17 @@
 #include "nsIFile.h"
 #include "nsIFileChannel.h"
 #include "nsIIOService.h"
 #include "nsILoadGroup.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsIStandardURL.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
+#include "nsStandardURL.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 
 NS_IMPL_ISUPPORTS(nsChromeProtocolHandler,
                   nsIProtocolHandler,
                   nsISupportsWeakReference)
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -64,42 +65,38 @@ nsChromeProtocolHandler::GetProtocolFlag
 }
 
 NS_IMETHODIMP
 nsChromeProtocolHandler::NewURI(const nsACString &aSpec,
                                 const char *aCharset,
                                 nsIURI *aBaseURI,
                                 nsIURI **result)
 {
-    nsresult rv;
 
     // Chrome: URLs (currently) have no additional structure beyond that provided
     // by standard URLs, so there is no "outer" given to CreateInstance
 
-    nsCOMPtr<nsIStandardURL> surl(do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
+    nsRefPtr<nsStandardURL> surl = new nsStandardURL();
 
-    rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec, aCharset, aBaseURI);
+    nsresult rv = surl->Init(nsIStandardURL::URLTYPE_STANDARD, -1, aSpec,
+                             aCharset, aBaseURI);
     if (NS_FAILED(rv))
         return rv;
 
-    nsCOMPtr<nsIURL> url(do_QueryInterface(surl, &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
-
     // Canonify the "chrome:" URL; e.g., so that we collapse
     // "chrome://navigator/content/" and "chrome://navigator/content"
     // and "chrome://navigator/content/navigator.xul".
 
-    rv = nsChromeRegistry::Canonify(url);
+    rv = nsChromeRegistry::Canonify(surl);
     if (NS_FAILED(rv))
         return rv;
 
     surl->SetMutable(false);
 
-    NS_ADDREF(*result = url);
+    surl.forget(result);
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsChromeProtocolHandler::NewChannel2(nsIURI* aURI,
                                      nsILoadInfo* aLoadInfo,
                                      nsIChannel** aResult)
 {