Skip to content

Commit 7edadc9

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 80098e6 commit 7edadc9

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,8 +4,8 @@
44
// message port.
55

66
const {
7-
ArrayPrototypeConcat,
87
ArrayPrototypeForEach,
8+
ArrayPrototypePushApply,
99
ArrayPrototypeSplice,
1010
ObjectDefineProperty,
1111
PromisePrototypeCatch,
@@ -126,7 +126,7 @@ port.on('message', (message) => {
126126
loadPreloadModules();
127127
initializeFrozenIntrinsics();
128128
if (argv !== undefined) {
129-
process.argv = ArrayPrototypeConcat(process.argv, argv);
129+
ArrayPrototypePushApply(process.argv, argv);
130130
}
131131
publicWorker.parentPort = publicPort;
132132
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,
@@ -1204,18 +1205,18 @@ Module._initPaths = function() {
12041205
path.resolve(process.execPath, '..') :
12051206
path.resolve(process.execPath, '..', '..');
12061207

1207-
let paths = [path.resolve(prefixDir, 'lib', 'node')];
1208+
const paths = [path.resolve(prefixDir, 'lib', 'node')];
12081209

12091210
if (homeDir) {
12101211
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_libraries'));
12111212
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_modules'));
12121213
}
12131214

12141215
if (nodePath) {
1215-
paths = ArrayPrototypeConcat(ArrayPrototypeFilter(
1216+
ArrayPrototypeUnshiftApply(paths, ArrayPrototypeFilter(
12161217
StringPrototypeSplit(nodePath, path.delimiter),
12171218
Boolean
1218-
), paths);
1219+
));
12191220
}
12201221

12211222
modulePaths = paths;

0 commit comments

Comments
 (0)