You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use String.prototype.repeat() to simplify code, less code,
more semantically.
PR-URL: nodejs#5359
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Copy file name to clipboardExpand all lines: benchmark/http_simple.js
+3-11Lines changed: 3 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ var http = require('http');
4
4
5
5
varport=parseInt(process.env.PORT||8000);
6
6
7
-
varfixed=makeString(20*1024,'C'),
7
+
varfixed='C'.repeat(20*1024),
8
8
storedBytes={},
9
9
storedBuffer={},
10
10
storedUnicode={};
@@ -42,7 +42,7 @@ var server = module.exports = http.createServer(function(req, res) {
42
42
if(n<=0)
43
43
thrownewError('bytes called with n <= 0');
44
44
if(storedBytes[n]===undefined){
45
-
storedBytes[n]=makeString(n,'C');
45
+
storedBytes[n]='C'.repeat(n);
46
46
}
47
47
body=storedBytes[n];
48
48
@@ -63,7 +63,7 @@ var server = module.exports = http.createServer(function(req, res) {
63
63
if(n<=0)
64
64
thrownewError('unicode called with n <= 0');
65
65
if(storedUnicode[n]===undefined){
66
-
storedUnicode[n]=makeString(n,'\u263A');
66
+
storedUnicode[n]='\u263A'.repeat(n);
67
67
}
68
68
body=storedUnicode[n];
69
69
@@ -107,14 +107,6 @@ var server = module.exports = http.createServer(function(req, res) {
107
107
}
108
108
});
109
109
110
-
functionmakeString(size,c){
111
-
vars='';
112
-
while(s.length<size){
113
-
s+=c;
114
-
}
115
-
returns;
116
-
}
117
-
118
110
server.listen(port,function(){
119
111
if(module===require.main)
120
112
console.error('Listening at http://127.0.0.1:'+port+'/');
0 commit comments