From e0f12d778681172b671fd97c08909c9ad4063724 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sat, 6 May 2017 18:49:19 -0400 Subject: [PATCH] Bug 1362806 - Optimize NS_GetDefaultPort() for HTTP(S); r=mcmanus --- netwerk/base/nsNetUtil.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netwerk/base/nsNetUtil.cpp b/netwerk/base/nsNetUtil.cpp index 5c8a10483639..47b82c17a225 100644 --- a/netwerk/base/nsNetUtil.cpp +++ b/netwerk/base/nsNetUtil.cpp @@ -476,6 +476,18 @@ NS_GetDefaultPort(const char *scheme, { 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 grip; net_EnsureIOService(&ioService, grip); if (!ioService)