Replace some Array.prototype-usage with spread syntax

We have a few, quite old, call-sites that use the `Array.prototype`-format and which can now be replaced with spread syntax instead.
This commit is contained in:
Jonas Jenwald 2022-09-23 09:35:30 +02:00
parent 91bdcd8b20
commit 6538409282
3 changed files with 6 additions and 17 deletions

View File

@ -1403,7 +1403,7 @@ class PartialEvaluator {
} else { } else {
const opArgs = operatorList.argsArray[lastIndex]; const opArgs = operatorList.argsArray[lastIndex];
opArgs[0].push(fn); opArgs[0].push(fn);
Array.prototype.push.apply(opArgs[1], args); opArgs[1].push(...args);
const minMax = opArgs[2]; const minMax = opArgs[2];
// Compute min/max in the worker instead of the main thread. // Compute min/max in the worker instead of the main thread.
@ -1910,17 +1910,11 @@ class PartialEvaluator {
self.ensureStateFont(stateManager.state); self.ensureStateFont(stateManager.state);
continue; continue;
} }
var arr = args[0];
var combinedGlyphs = []; var combinedGlyphs = [];
var arrLength = arr.length;
var state = stateManager.state; var state = stateManager.state;
for (i = 0; i < arrLength; ++i) { for (const arrItem of args[0]) {
const arrItem = arr[i];
if (typeof arrItem === "string") { if (typeof arrItem === "string") {
Array.prototype.push.apply( combinedGlyphs.push(...self.handleText(arrItem, state));
combinedGlyphs,
self.handleText(arrItem, state)
);
} else if (typeof arrItem === "number") { } else if (typeof arrItem === "number") {
combinedGlyphs.push(arrItem); combinedGlyphs.push(arrItem);
} }

View File

@ -523,9 +523,7 @@ class PostScriptStack {
} }
constructor(initialStack) { constructor(initialStack) {
this.stack = !initialStack this.stack = initialStack ? Array.from(initialStack) : [];
? []
: Array.prototype.slice.call(initialStack, 0);
} }
push(value) { push(value) {
@ -1201,10 +1199,7 @@ class PostScriptCompiler {
if (j === 0) { if (j === 0) {
break; // just skipping -- there are nothing to rotate break; // just skipping -- there are nothing to rotate
} }
Array.prototype.push.apply( stack.push(...stack.splice(stack.length - n, n - j));
stack,
stack.splice(stack.length - n, n - j)
);
break; break;
default: default:
return null; // unsupported operator return null; // unsupported operator

View File

@ -419,7 +419,7 @@ describe("function", function () {
for (const { input, output } of samples) { for (const { input, output } of samples) {
const out = new Float32Array(output.length); const out = new Float32Array(output.length);
fn(input, 0, out, 0); fn(input, 0, out, 0);
expect(Array.prototype.slice.call(out, 0)).toEqual(output); expect(Array.from(out)).toEqual(output);
} }
} }
} }