From aba6bc34a186ff03ff19a1b4026e04cea7c330e3 Mon Sep 17 00:00:00 2001 From: Seth Brenith Date: Tue, 23 Jan 2018 16:04:17 -0800 Subject: http: switch on string values Long ago, V8 was much faster switching on string lengths than values. That is no longer the case, so we can simplify a couple of methods. PR-URL: https://github.com/nodejs/node/pull/18351 Reviewed-By: James M Snell Reviewed-By: Kyle Farnung Reviewed-By: Anatoli Papirovski Reviewed-By: Gireesh Punathil Reviewed-By: Colin Ihrig Reviewed-By: Jon Moss --- lib/_http_outgoing.js | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) (limited to 'lib/_http_outgoing.js') diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index 79d38db291..5f4e8e2cf1 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -510,18 +510,15 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) { const key = name.toLowerCase(); this[outHeadersKey][key] = [name, value]; - switch (key.length) { - case 10: - if (key === 'connection') - this._removedConnection = false; + switch (key) { + case 'connection': + this._removedConnection = false; break; - case 14: - if (key === 'content-length') - this._removedContLen = false; + case 'content-length': + this._removedContLen = false; break; - case 17: - if (key === 'transfer-encoding') - this._removedTE = false; + case 'transfer-encoding': + this._removedTE = false; break; } }; @@ -583,22 +580,18 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) { var key = name.toLowerCase(); - switch (key.length) { - case 10: - if (key === 'connection') - this._removedConnection = true; + switch (key) { + case 'connection': + this._removedConnection = true; break; - case 14: - if (key === 'content-length') - this._removedContLen = true; + case 'content-length': + this._removedContLen = true; break; - case 17: - if (key === 'transfer-encoding') - this._removedTE = true; + case 'transfer-encoding': + this._removedTE = true; break; - case 4: - if (key === 'date') - this.sendDate = false; + case 'date': + this.sendDate = false; break; } -- cgit v1.2.3