Skip to content

Commit

Permalink
http: simplify isInvalidPath
Browse files Browse the repository at this point in the history
The loop unrolling shows no performance benefits in V8 6.3.
This change is to simplify `isInvalidPath` without performance
regression.
  • Loading branch information
starkwang committed Dec 7, 2017
1 parent 8514ea9 commit cdafdf3
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,7 @@ const errors = require('internal/errors');
// This function is used in the case of small paths, where manual character code
// checks can greatly outperform the equivalent regexp (tested in V8 5.4).
function isInvalidPath(s) {
var i = 0;
if (s.charCodeAt(0) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(1) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(2) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(3) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(4) <= 32) return true;
if (++i >= s.length) return false;
if (s.charCodeAt(5) <= 32) return true;
++i;
for (; i < s.length; ++i)
for (var i = 0; i < s.length; ++i)
if (s.charCodeAt(i) <= 32) return true;
return false;
}
Expand Down

0 comments on commit cdafdf3

Please sign in to comment.