Bug 1362806 - Optimize NS_GetDefaultPort() for HTTP(S); r=mcmanus
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 06 May 2017 18:49:19 -0400
changeset 357000 98d1dd932bc67a9121fdec38aebe800f11a4a3e4
parent 356999 6086ceba2e8c787768266479d694806725e90add
child 357001 f30e35f881920a7acdb1dd1eb6deaa2f37a785b6
push id31778
push usercbook@mozilla.com
push dateMon, 08 May 2017 08:07:41 +0000
treeherdermozilla-central@1fda52a1f3b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus
bugs1362806
milestone55.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 1362806 - Optimize NS_GetDefaultPort() for HTTP(S); r=mcmanus
netwerk/base/nsNetUtil.cpp
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -471,16 +471,28 @@ NS_MakeAbsoluteURI(nsAString       &resu
 }
 
 int32_t
 NS_GetDefaultPort(const char *scheme,
                   nsIIOService *ioService /* = nullptr */)
 {
   nsresult rv;
 
+  // Getting the default port through the protocol handler has a lot of XPCOM
+  // overhead involved.  We optimize the protocols that matter for Web pages
+  // (HTTP and HTTPS) by hardcoding their default ports here.
+  if (strncmp(scheme, "http", 4) == 0) {
+    if (scheme[4] == 's' && scheme[5] == '\0') {
+      return 443;
+    }
+    if (scheme[4] == '\0') {
+      return 80;
+    }
+  }
+
   nsCOMPtr<nsIIOService> grip;
   net_EnsureIOService(&ioService, grip);
   if (!ioService)
       return -1;
 
   nsCOMPtr<nsIProtocolHandler> handler;
   rv = ioService->GetProtocolHandler(scheme, getter_AddRefs(handler));
   if (NS_FAILED(rv))