Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
url: remove unused code from autoEscapeStr
  • Loading branch information
cyril-lakech committed Aug 30, 2017
commit 2333e4c15b16c34817387381fa89704923ee5094
15 changes: 5 additions & 10 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,7 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) {
// First, make 100% sure that any "autoEscape" chars get
// escaped, even if encodeURIComponent doesn't think they
// need to be.
const result = autoEscapeStr(rest);
if (result !== undefined)
rest = result;
rest = autoEscapeStr(rest);
}

var questionIdx = -1;
Expand Down Expand Up @@ -443,8 +441,7 @@ function validateHostname(self, rest, hostname) {

// Automatically escape all delimiters and unwise characters from RFC 2396.
// Also escape single quotes in case of an XSS attack.
// Return undefined if the string doesn't need escaping,
// otherwise return the escaped string.
// Return the escaped string.
function autoEscapeStr(rest) {
var escaped = '';
var lastEscapedPos = 0;
Expand Down Expand Up @@ -539,13 +536,11 @@ function autoEscapeStr(rest) {
break;
}
}
if (lastEscapedPos === 0) // Nothing has been escaped.
return;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check if it is a good idea to keep the if but return rest here.

Copy link
Copy Markdown
Contributor Author

@clakech clakech Aug 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tried with this check and here is the perf result:

node benchmark/compare.js --old ../node/out/Release/node --new out/Release/node --filter legacy-vs-whatwg-url-parse.js --runs 10 --set method=legacy url > result.csv
[00:03:31|% 100| 1/1 files | 20/20 runs | 9/9 configs]: Done

cat result.csv | Rscript benchmark/compare.R
                                                                              improvement confidence   p.value
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="auth"           -2.80 %            0.8940666
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="dot"            10.52 %            0.5992881
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="file"           -5.34 %            0.7988524
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="idn"            -3.03 %            0.8843592
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="javascript"      7.21 %            0.7159490
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="long"           -3.54 %            0.8643568
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="percent"        11.36 %            0.5700568
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="short"          -2.29 %            0.9104903
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="ws"             11.91 %            0.5628974

Copy link
Copy Markdown
Contributor Author

@clakech clakech Aug 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I retry with --runs 100 and now this is better:

cat result.csv | Rscript benchmark/compare.R
                                                                              improvement confidence   p.value
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="auth"           -0.99 %            0.2587248
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="dot"            -0.50 %            0.6006786
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="file"            0.87 %            0.3582855
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="idn"             0.03 %            0.9783704
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="javascript"     -0.58 %            0.5305400
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="long"           -0.20 %            0.7804390
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="percent"         1.31 %            0.1699119
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="short"           0.47 %            0.5801138
 url/legacy-vs-whatwg-url-parse.js n=100000 method="legacy" type="ws"             -0.57 %            0.5023730

// There are ordinary characters at the end.
if (lastEscapedPos < rest.length)
return escaped + rest.slice(lastEscapedPos);
else // The last character is escaped.
return escaped;
escaped += rest.slice(lastEscapedPos);

return escaped;
}

// format a parsed object into a url string
Expand Down