Skip to content

Commit 36aeae8

Browse files
CGavrilabnoordhuis
authored andcommitted
url: improve parsing speed
The url.parse() function now checks whether an escapable character is in the URL before trying to escape it. PR-URL: nodejs/node-v0.x-archive#8638 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 244a8f7 commit 36aeae8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/url.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,13 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
319319
// need to be.
320320
for (var i = 0, l = autoEscape.length; i < l; i++) {
321321
var ae = autoEscape[i];
322-
var esc = encodeURIComponent(ae);
323-
if (esc === ae) {
324-
esc = escape(ae);
322+
if (rest.indexOf(ae) !== -1) {
323+
var esc = encodeURIComponent(ae);
324+
if (esc === ae) {
325+
esc = escape(ae);
326+
}
327+
rest = rest.split(ae).join(esc);
325328
}
326-
rest = rest.split(ae).join(esc);
327329
}
328330
}
329331

0 commit comments

Comments
 (0)