Skip to content

Commit cdafdf3

Browse files
committed
http: simplify isInvalidPath
The loop unrolling shows no performance benefits in V8 6.3. This change is to simplify `isInvalidPath` without performance regression.
1 parent 8514ea9 commit cdafdf3

File tree

1 file changed

+1
-14
lines changed

1 file changed

+1
-14
lines changed

lib/_http_client.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,7 @@ const errors = require('internal/errors');
5151
// This function is used in the case of small paths, where manual character code
5252
// checks can greatly outperform the equivalent regexp (tested in V8 5.4).
5353
function isInvalidPath(s) {
54-
var i = 0;
55-
if (s.charCodeAt(0) <= 32) return true;
56-
if (++i >= s.length) return false;
57-
if (s.charCodeAt(1) <= 32) return true;
58-
if (++i >= s.length) return false;
59-
if (s.charCodeAt(2) <= 32) return true;
60-
if (++i >= s.length) return false;
61-
if (s.charCodeAt(3) <= 32) return true;
62-
if (++i >= s.length) return false;
63-
if (s.charCodeAt(4) <= 32) return true;
64-
if (++i >= s.length) return false;
65-
if (s.charCodeAt(5) <= 32) return true;
66-
++i;
67-
for (; i < s.length; ++i)
54+
for (var i = 0; i < s.length; ++i)
6855
if (s.charCodeAt(i) <= 32) return true;
6956
return false;
7057
}

0 commit comments

Comments
 (0)