From 99eef5f3a4fa2c60ca324b4dfccce6ef6f0a6c4f Mon Sep 17 00:00:00 2001 From: CGavrila Date: Tue, 28 Oct 2014 12:08:37 +0000 Subject: [PATCH] url: improve parsing speed The url.parse() function now checks whether an escapable character is in the URL before trying to escape it. --- lib/url.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/url.js b/lib/url.js index 4c0ef0102fad..2a0b7abee6e4 100644 --- a/lib/url.js +++ b/lib/url.js @@ -309,11 +309,13 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { // need to be. for (var i = 0, l = autoEscape.length; i < l; i++) { var ae = autoEscape[i]; - var esc = encodeURIComponent(ae); - if (esc === ae) { - esc = escape(ae); + if (rest.indexOf(ae) !== -1) { + var esc = encodeURIComponent(ae); + if (esc === ae) { + esc = escape(ae); + } + rest = rest.split(ae).join(esc); } - rest = rest.split(ae).join(esc); } }