Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d764039

Browse filesBrowse files
sethbrenithMylesBorins
authored andcommitted
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: #18351 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
1 parent b5267a6 commit d764039
Copy full SHA for d764039

File tree

Expand file treeCollapse file tree

2 files changed

+46
-23
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+46
-23
lines changed
Open diff view settings
Collapse file

‎benchmark/http/set_header.js‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const { OutgoingMessage } = require('_http_outgoing');
5+
6+
const bench = common.createBenchmark(main, {
7+
value: [
8+
'X-Powered-By',
9+
'Vary',
10+
'Set-Cookie',
11+
'Content-Type',
12+
'Content-Length',
13+
'Connection',
14+
'Transfer-Encoding'
15+
],
16+
n: [1e6],
17+
});
18+
19+
function main(conf) {
20+
const n = +conf.n;
21+
const value = conf.value;
22+
23+
const og = new OutgoingMessage();
24+
25+
bench.start();
26+
for (var i = 0; i < n; i++) {
27+
og.setHeader(value, '');
28+
}
29+
bench.end(n);
30+
}
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+16-23Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -515,18 +515,15 @@ OutgoingMessage.prototype.setHeader = function setHeader(name, value) {
515515
const key = name.toLowerCase();
516516
this[outHeadersKey][key] = [name, value];
517517

518-
switch (key.length) {
519-
case 10:
520-
if (key === 'connection')
521-
this._removedConnection = false;
518+
switch (key) {
519+
case 'connection':
520+
this._removedConnection = false;
522521
break;
523-
case 14:
524-
if (key === 'content-length')
525-
this._removedContLen = false;
522+
case 'content-length':
523+
this._removedContLen = false;
526524
break;
527-
case 17:
528-
if (key === 'transfer-encoding')
529-
this._removedTE = false;
525+
case 'transfer-encoding':
526+
this._removedTE = false;
530527
break;
531528
}
532529
};
@@ -588,22 +585,18 @@ OutgoingMessage.prototype.removeHeader = function removeHeader(name) {
588585

589586
var key = name.toLowerCase();
590587

591-
switch (key.length) {
592-
case 10:
593-
if (key === 'connection')
594-
this._removedConnection = true;
588+
switch (key) {
589+
case 'connection':
590+
this._removedConnection = true;
595591
break;
596-
case 14:
597-
if (key === 'content-length')
598-
this._removedContLen = true;
592+
case 'content-length':
593+
this._removedContLen = true;
599594
break;
600-
case 17:
601-
if (key === 'transfer-encoding')
602-
this._removedTE = true;
595+
case 'transfer-encoding':
596+
this._removedTE = true;
603597
break;
604-
case 4:
605-
if (key === 'date')
606-
this.sendDate = false;
598+
case 'date':
599+
this.sendDate = false;
607600
break;
608601
}
609602

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.