diff --git a/lib/child_process.js b/lib/child_process.js index 5ceed97b57b3..43d278322b58 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -31,7 +31,7 @@ const { ArrayPrototypePushApply, ArrayPrototypeSlice, ArrayPrototypeSort, - ArrayPrototypeSplice, + ArrayPrototypeToSpliced, ArrayPrototypeUnshift, ObjectAssign, ObjectDefineProperty, @@ -157,8 +157,7 @@ function fork(modulePath, args = [], options) { const index = ArrayPrototypeLastIndexOf(execArgv, process._eval); if (index > 0) { // Remove the -e switch to avoid fork bombing ourselves. - execArgv = ArrayPrototypeSlice(execArgv); - ArrayPrototypeSplice(execArgv, index - 1, 2); + execArgv = ArrayPrototypeToSpliced(execArgv, index - 1, 2); } } diff --git a/lib/domain.js b/lib/domain.js index caf97983b8f8..2af43ffaef7c 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -33,6 +33,7 @@ const { ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSplice, + ArrayPrototypeToSpliced, Error, FunctionPrototypeCall, ObjectDefineProperty, @@ -391,8 +392,7 @@ Domain.prototype.enter = function() { // Note that this might be a no-op, but we still need // to push it onto the stack so that we can pop it later. const currentStore = getDomainStore() || { domain: null, stack: [] }; - const newStack = ArrayPrototypeSlice(currentStore.stack); - ArrayPrototypePush(newStack, this); + const newStack = ArrayPrototypeToSpliced(currentStore.stack, currentStore.stack.length, 0, this); setDomainStore({ domain: this, stack: newStack }); exports.active = this; currentDomain = this; @@ -471,8 +471,7 @@ Domain.prototype.remove = function(ee) { // exit() only runs on success. function runInDomain(domain, thisArg, fn, args) { const currentStore = getDomainStore() || { domain: null, stack: [] }; - const newStack = ArrayPrototypeSlice(currentStore.stack); - ArrayPrototypePush(newStack, domain); + const newStack = ArrayPrototypeToSpliced(currentStore.stack, currentStore.stack.length, 0, domain); const previousDomain = currentDomain; const previousStack = currentStack; diff --git a/lib/internal/bench_runner/benchmark.js b/lib/internal/bench_runner/benchmark.js index 114feb388172..acb92d1d6ca9 100644 --- a/lib/internal/bench_runner/benchmark.js +++ b/lib/internal/bench_runner/benchmark.js @@ -7,6 +7,7 @@ const { ArrayPrototypeReverse, ArrayPrototypeSlice, ArrayPrototypeSort, + ArrayPrototypeToSorted, Float64Array, JSONStringify, MathFloor, @@ -532,8 +533,7 @@ function summarizeSamples(samples) { variance /= rates.length; const stddev = MathSqrt(variance); - const sorted = ArrayPrototypeSlice(rates); - ArrayPrototypeSort(sorted, (a, b) => a - b); + const sorted = ArrayPrototypeToSorted(rates, (a, b) => a - b); const middle = MathFloor(sorted.length / 2); const median = sorted.length % 2 === 0 ? (sorted[middle - 1] + sorted[middle]) / 2 : sorted[middle]; diff --git a/lib/internal/debugger/inspect_probe.js b/lib/internal/debugger/inspect_probe.js index 3b77a46f1ba1..99edbb8087e0 100644 --- a/lib/internal/debugger/inspect_probe.js +++ b/lib/internal/debugger/inspect_probe.js @@ -8,6 +8,7 @@ const { ArrayPrototypePush, ArrayPrototypeSlice, ArrayPrototypeSome, + ArrayPrototypeToSpliced, FunctionPrototypeBind, JSONStringify, NumberIsNaN, @@ -989,8 +990,7 @@ class ProbeInspectorSession { } buildReport({ exitCode, terminal }) { - const results = ArrayPrototypeSlice(this.results); - ArrayPrototypePush(results, terminal); + const results = ArrayPrototypeToSpliced(this.results, this.results.length, 0, terminal); return { code: exitCode, report: { diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index 9366eb13543e..7136b43cc042 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -1,6 +1,7 @@ 'use strict'; const { + ArrayPrototypeToSorted, BigInt, Float64Array, Map, @@ -596,7 +597,7 @@ class Histogram { throw new ERR_OUT_OF_RANGE( `percentiles[${i}]`, '> 0 && <= 100', percentiles[i]); } - const sorted = [...percentiles].sort((a, b) => a - b); + const sorted = ArrayPrototypeToSorted(percentiles, (a, b) => a - b); const input = new Float64Array(sorted); const map = new Map(); this[kHandle]?.percentilesAt(map, input); diff --git a/lib/internal/zip/entry.js b/lib/internal/zip/entry.js index 5ac649c4f489..13e31496f020 100644 --- a/lib/internal/zip/entry.js +++ b/lib/internal/zip/entry.js @@ -7,8 +7,7 @@ const { ArrayPrototypePush, - ArrayPrototypeSlice, - ArrayPrototypeSort, + ArrayPrototypeToSorted, Date, DateNow, JSONStringify, @@ -1057,7 +1056,7 @@ function* readArchiveEntries(buf, end) { } // Sort a separate range list; entries themselves are yielded in central // directory order. - const ranges = ArrayPrototypeSort(ArrayPrototypeSlice(parsed), (a, b) => a.start - b.start); + const ranges = ArrayPrototypeToSorted(parsed, (a, b) => a.start - b.start); for (let i = 0; i < ranges.length; i++) { const bound = i + 1 < ranges.length ? ranges[i + 1].start : end.centralDirectoryOffset; if (ranges[i].dataEnd > bound) {