Skip to content

Commit a8cf47e

Browse files
committed
lib: use <array>.push and <array>.unshift instead of <array>.concat
Using `push` and `unshift` methods is more performant than reassigning a new array created with `concat`.
1 parent 2e769a9 commit a8cf47e

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

lib/_http_common.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'use strict';
2323

2424
const {
25-
ArrayPrototypeConcat,
25+
ArrayPrototypePushApply,
2626
MathMin,
2727
Symbol,
2828
RegExpPrototypeTest,
@@ -66,7 +66,7 @@ function parserOnHeaders(headers, url) {
6666
// Once we exceeded headers limit - stop collecting them
6767
if (this.maxHeaderPairs <= 0 ||
6868
this._headers.length < this.maxHeaderPairs) {
69-
this._headers = ArrayPrototypeConcat(this._headers, headers);
69+
ArrayPrototypePushApply(this._headers, headers);
7070
}
7171
this._url += url;
7272
}

lib/internal/main/worker_thread.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// message port.
55

66
const {
7-
ArrayPrototypeConcat,
7+
ArrayPrototypePushApply,
88
ArrayPrototypeSplice,
99
ObjectDefineProperty,
1010
PromisePrototypeCatch,
@@ -125,7 +125,7 @@ port.on('message', (message) => {
125125
loadPreloadModules();
126126
initializeFrozenIntrinsics();
127127
if (argv !== undefined) {
128-
process.argv = ArrayPrototypeConcat(process.argv, argv);
128+
ArrayPrototypePushApply(process.argv, argv);
129129
}
130130
publicWorker.parentPort = publicPort;
131131
publicWorker.workerData = workerData;

lib/internal/modules/cjs/loader.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const {
3232
ArrayPrototypeSlice,
3333
ArrayPrototypeSplice,
3434
ArrayPrototypeUnshift,
35+
ArrayPrototypeUnshiftApply,
3536
Boolean,
3637
Error,
3738
JSONParse,
@@ -1225,18 +1226,18 @@ Module._initPaths = function() {
12251226
path.resolve(process.execPath, '..') :
12261227
path.resolve(process.execPath, '..', '..');
12271228

1228-
let paths = [path.resolve(prefixDir, 'lib', 'node')];
1229+
const paths = [path.resolve(prefixDir, 'lib', 'node')];
12291230

12301231
if (homeDir) {
12311232
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_libraries'));
12321233
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_modules'));
12331234
}
12341235

12351236
if (nodePath) {
1236-
paths = ArrayPrototypeConcat(ArrayPrototypeFilter(
1237+
ArrayPrototypeUnshiftApply(paths, ArrayPrototypeFilter(
12371238
StringPrototypeSplit(nodePath, path.delimiter),
12381239
Boolean
1239-
), paths);
1240+
));
12401241
}
12411242

12421243
modulePaths = paths;

0 commit comments

Comments
 (0)