Skip to content

Commit c449eb5

Browse files
apapirovskijasnell
authored andcommitted
http: simplify isCookieField
Handrolling and checking char by char is no longer faster than just using toLowerCase and strict comparison. PR-URL: #20131 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent f4a559b commit c449eb5

File tree

1 file changed

+3
-17
lines changed

1 file changed

+3
-17
lines changed

lib/_http_outgoing.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,10 @@ var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig;
5858
var RE_TE_CHUNKED = common.chunkExpression;
5959

6060
// isCookieField performs a case-insensitive comparison of a provided string
61-
// against the word "cookie." This method (at least as of V8 5.4) is faster than
62-
// the equivalent case-insensitive regexp, even if isCookieField does not get
63-
// inlined.
61+
// against the word "cookie." As of V8 6.6 this is faster than handrolling or
62+
// using a case-insensitive RegExp.
6463
function isCookieField(s) {
65-
if (s.length !== 6) return false;
66-
var ch = s.charCodeAt(0);
67-
if (ch !== 99 && ch !== 67) return false;
68-
ch = s.charCodeAt(1);
69-
if (ch !== 111 && ch !== 79) return false;
70-
ch = s.charCodeAt(2);
71-
if (ch !== 111 && ch !== 79) return false;
72-
ch = s.charCodeAt(3);
73-
if (ch !== 107 && ch !== 75) return false;
74-
ch = s.charCodeAt(4);
75-
if (ch !== 105 && ch !== 73) return false;
76-
ch = s.charCodeAt(5);
77-
if (ch !== 101 && ch !== 69) return false;
78-
return true;
64+
return s.length === 6 && s.toLowerCase() === 'cookie';
7965
}
8066

8167
function noopPendingOutput(amount) {}

0 commit comments

Comments
 (0)