From db0174bbc86c86b8e22c37977c88ddced559ad79 Mon Sep 17 00:00:00 2001 From: Anatoli Papirovski Date: Wed, 18 Apr 2018 14:57:28 +0200 Subject: [PATCH] http: simplify isCookieField Handrolling and checking char by char is no longer faster than just using toLowerCase and strict comparison. PR-URL: https://github.com/nodejs/node/pull/20131 Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Yuta Hiroto Reviewed-By: Ruben Bridgewater --- lib/_http_outgoing.js | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index b62dea4a24d..8ed49401960 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -58,24 +58,10 @@ var RE_CONN_VALUES = /(?:^|\W)close|upgrade(?:$|\W)/ig; var RE_TE_CHUNKED = common.chunkExpression; // isCookieField performs a case-insensitive comparison of a provided string -// against the word "cookie." This method (at least as of V8 5.4) is faster than -// the equivalent case-insensitive regexp, even if isCookieField does not get -// inlined. +// against the word "cookie." As of V8 6.6 this is faster than handrolling or +// using a case-insensitive RegExp. function isCookieField(s) { - if (s.length !== 6) return false; - var ch = s.charCodeAt(0); - if (ch !== 99 && ch !== 67) return false; - ch = s.charCodeAt(1); - if (ch !== 111 && ch !== 79) return false; - ch = s.charCodeAt(2); - if (ch !== 111 && ch !== 79) return false; - ch = s.charCodeAt(3); - if (ch !== 107 && ch !== 75) return false; - ch = s.charCodeAt(4); - if (ch !== 105 && ch !== 73) return false; - ch = s.charCodeAt(5); - if (ch !== 101 && ch !== 69) return false; - return true; + return s.length === 6 && s.toLowerCase() === 'cookie'; } function noopPendingOutput(amount) {}