Skip to content

Commit

Permalink
lib: use <array>.push and <array>.unshift instead of <array>.concat
Browse files Browse the repository at this point in the history
Using `push` and `unshift` methods is more performant than reassigning a
new array created with `concat`.

PR-URL: #37239
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Feb 28, 2021
1 parent a3e3156 commit bb81acc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/_http_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
'use strict';

const {
ArrayPrototypeConcat,
ArrayPrototypePushApply,
MathMin,
Symbol,
RegExpPrototypeTest,
Expand Down Expand Up @@ -66,7 +66,7 @@ function parserOnHeaders(headers, url) {
// Once we exceeded headers limit - stop collecting them
if (this.maxHeaderPairs <= 0 ||
this._headers.length < this.maxHeaderPairs) {
this._headers = ArrayPrototypeConcat(this._headers, headers);
ArrayPrototypePushApply(this._headers, headers);
}
this._url += url;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// message port.

const {
ArrayPrototypeConcat,
ArrayPrototypeForEach,
ArrayPrototypePushApply,
ArrayPrototypeSplice,
ObjectDefineProperty,
PromisePrototypeCatch,
Expand Down Expand Up @@ -126,7 +126,7 @@ port.on('message', (message) => {
loadPreloadModules();
initializeFrozenIntrinsics();
if (argv !== undefined) {
process.argv = ArrayPrototypeConcat(process.argv, argv);
ArrayPrototypePushApply(process.argv, argv);
}
publicWorker.parentPort = publicPort;
publicWorker.workerData = workerData;
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const {
ArrayPrototypeSlice,
ArrayPrototypeSplice,
ArrayPrototypeUnshift,
ArrayPrototypeUnshiftApply,
Boolean,
Error,
JSONParse,
Expand Down Expand Up @@ -1208,18 +1209,18 @@ Module._initPaths = function() {
path.resolve(process.execPath, '..') :
path.resolve(process.execPath, '..', '..');

let paths = [path.resolve(prefixDir, 'lib', 'node')];
const paths = [path.resolve(prefixDir, 'lib', 'node')];

if (homeDir) {
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_libraries'));
ArrayPrototypeUnshift(paths, path.resolve(homeDir, '.node_modules'));
}

if (nodePath) {
paths = ArrayPrototypeConcat(ArrayPrototypeFilter(
ArrayPrototypeUnshiftApply(paths, ArrayPrototypeFilter(
StringPrototypeSplit(nodePath, path.delimiter),
Boolean
), paths);
));
}

modulePaths = paths;
Expand Down

0 comments on commit bb81acc

Please sign in to comment.