diff options
author | gorhill <rhill@raymondhill.net> | 2015-01-14 19:43:10 -0500 |
---|---|---|
committer | gorhill <rhill@raymondhill.net> | 2015-01-14 19:43:10 -0500 |
commit | 119a98026c49714ac8c9b3547640763d78cb22f5 (patch) | |
tree | e32c93cd686610bff1979e6e4987a3cb9da5bc30 /platform | |
parent | ee01803419fb36fa0acf9f04bb2a87fffa11ea53 (diff) | |
download | uBlock-119a98026c49714ac8c9b3547640763d78cb22f5.zip uBlock-119a98026c49714ac8c9b3547640763d78cb22f5.tar.gz uBlock-119a98026c49714ac8c9b3547640763d78cb22f5.tar.bz2 |
code review re #498
Diffstat (limited to 'platform')
-rw-r--r-- | platform/firefox/vapi-background.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index ec7055e..56f185c 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1478,12 +1478,24 @@ window.addEventListener('unload', function() { /******************************************************************************/ -var urlNormalizer = self.URL; -var punycodeHostname = vAPI.punycodeHostname = punycode.toASCII; +// Likelihood is that we do not have to punycode: given punycode overhead, +// it's faster to check and skip than do it unconditionally all the time. + +var punycodeHostname = punycode.toASCII; +var isNotASCII = /[^\x21-\x7F]/; + +vAPI.punycodeHostname = function(hostname) { + return isNotASCII.test(hostname) ? punycodeHostname(hostname) : hostname; +}; + +var cachedURL = self.URL; vAPI.punycodeURL = function(url) { - urlNormalizer.href = url; - urlNormalizer.hostname = punycodeHostname(urlNormalizer.hostname); + if ( isNotASCII.test(url) === false ) { + return url; + } + cachedURL.href = url; + cachedURL.hostname = punycodeHostname(cachedURL.hostname); return urlNormalizer.href; }; |