Bug 998372 - part 2 - lift origins out of FindProxyForURL and make origin lookups more efficient; r=jmaher
authorNathan Froyd <froydnj@mozilla.com>
Fri, 18 Apr 2014 12:17:15 -0400
changeset 199176 43c5d06184bba1ac42cd0e7ae5c69d30a34a7bd4
parent 199175 0c24e6699b718eba5ee7442b71b11c7364088fa2
child 199177 cbbf7905937be8859e933efbef16394888606bde
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs998372
milestone31.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 998372 - part 2 - lift origins out of FindProxyForURL and make origin lookups more efficient; r=jmaher
testing/mozbase/mozprofile/mozprofile/permissions.py
testing/mozbase/mozprofile/tests/permissions.py
--- a/testing/mozbase/mozprofile/mozprofile/permissions.py
+++ b/testing/mozbase/mozprofile/mozprofile/permissions.py
@@ -303,25 +303,27 @@ class Permissions(object):
         if isinstance(user_proxy, dict):
             proxy.update(user_proxy)
 
         # TODO: this should live in a template!
         # TODO: So changing the 5th line of the regex below from (\\\\\\\\d+)
         # to (\\\\d+) makes this code work. Not sure why there would be this
         # difference between automation.py.in and this file.
         pacURL = """data:text/plain,
+var knownOrigins = (function () {
+  return [%(origins)s].reduce(function(t, h) { t[h] = true; return t; }, {})
+})();
 var uriRegex = new RegExp('^([a-z][-a-z0-9+.]*)' +
                           '://' +
                           '(?:[^/@]*@)?' +
                           '(.*?)' +
                           '(?::(\\\\d+))?/');
 
 function FindProxyForURL(url, host)
 {
-  var origins = [%(origins)s];
   var matches = uriRegex.exec(url);
   if (!matches)
     return 'DIRECT';
   var isHttp = matches[1] == 'http';
   var isHttps = matches[1] == 'https';
   var isWebSocket = matches[1] == 'ws';
   var isWebSocketSSL = matches[1] == 'wss';
   if (!matches[3])
@@ -330,17 +332,17 @@ function FindProxyForURL(url, host)
     if (isHttps | isWebSocketSSL) matches[3] = '443';
   }
   if (isWebSocket)
     matches[1] = 'http';
   if (isWebSocketSSL)
     matches[1] = 'https';
 
   var origin = matches[1] + '://' + matches[2] + ':' + matches[3];
-  if (origins.indexOf(origin) < 0)
+  if (!(origin in knownOrigins))
     return 'DIRECT';
   if (isHttp) return 'PROXY %(remote)s:%(http)s';
   if (isHttps) return 'PROXY %(remote)s:%(https)s';
   if (isWebSocket) return 'PROXY %(remote)s:%(ws)s';
   if (isWebSocketSSL) return 'PROXY %(remote)s:%(wss)s';
   return 'DIRECT';
 }""" % proxy
         pacURL = "".join(pacURL.splitlines())
old mode 100644
new mode 100755
--- a/testing/mozbase/mozprofile/tests/permissions.py
+++ b/testing/mozbase/mozprofile/tests/permissions.py
@@ -118,17 +118,17 @@ http://127.0.0.1:8888           privileg
         self.assertEqual(len(user_prefs), 0)
         self.assertEqual(len(prefs), 0)
 
         prefs, user_prefs = perms.network_prefs(True)
         self.assertEqual(len(user_prefs), 2)
         self.assertEqual(user_prefs[0], ('network.proxy.type', 2))
         self.assertEqual(user_prefs[1][0], 'network.proxy.autoconfig_url')
 
-        origins_decl = "var origins = ['http://mochi.test:8888', 'http://127.0.0.1:80', 'http://127.0.0.1:8888'];"
+        origins_decl = "var knownOrigins = (function () {  return ['http://mochi.test:8888', 'http://127.0.0.1:80', 'http://127.0.0.1:8888'].reduce"
         self.assertTrue(origins_decl in user_prefs[1][1])
 
         proxy_check = ("if (isHttp) return 'PROXY mochi.test:8888';",
                        "if (isHttps) return 'PROXY mochi.test:4443';",
                        "if (isWebSocket) return 'PROXY mochi.test:4443';",
                        "if (isWebSocketSSL) return 'PROXY mochi.test:4443';")
         self.assertTrue(all(c in user_prefs[1][1] for c in proxy_check))