Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce unnecessary usage of Array.prototype.concat() #15059

Merged
merged 1 commit into from
Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,11 @@ function postprocessNode(ctx, node) {
case "BlockStatement":
// Block statements inside a block are moved to the parent one.
const subChildren = node.body[subExpressionIndex].body;
Array.prototype.splice.apply(
node.body,
[subExpressionIndex, 1].concat(subChildren)
);
Array.prototype.splice.apply(node.body, [
subExpressionIndex,
1,
...subChildren,
]);
subExpressionIndex += Math.max(subChildren.length - 1, 0);
continue;
case "ReturnStatement":
Expand Down
14 changes: 7 additions & 7 deletions src/core/cff_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ class CFFCompiler {
const output = {
data: [],
length: 0,
add: function CFFCompiler_add(data) {
add(data) {
this.data = this.data.concat(data);
this.length = this.data.length;
},
Expand Down Expand Up @@ -1680,7 +1680,7 @@ class CFFCompiler {
}

compileDict(dict, offsetTracker) {
let out = [];
const out = [];
// The dictionary keys must be in a certain order.
const order = dict.order;
for (let i = 0; i < order.length; ++i) {
Expand Down Expand Up @@ -1708,7 +1708,7 @@ class CFFCompiler {
switch (type) {
case "num":
case "sid":
out = out.concat(this.encodeNumber(value));
out.push(...this.encodeNumber(value));
break;
case "offset":
// For offsets we just insert a 32bit integer so we don't have to
Expand All @@ -1720,20 +1720,20 @@ class CFFCompiler {
if (!offsetTracker.isTracking(name)) {
offsetTracker.track(name, out.length);
}
out = out.concat([0x1d, 0, 0, 0, 0]);
out.push(0x1d, 0, 0, 0, 0);
break;
case "array":
case "delta":
out = out.concat(this.encodeNumber(value));
out.push(...this.encodeNumber(value));
for (let k = 1, kk = values.length; k < kk; ++k) {
out = out.concat(this.encodeNumber(values[k]));
out.push(...this.encodeNumber(values[k]));
}
break;
default:
throw new FormatError(`Unknown data type of ${type}`);
}
}
out = out.concat(dict.opcodes[key]);
out.push(...dict.opcodes[key]);
}
return out;
}
Expand Down
16 changes: 8 additions & 8 deletions src/core/jbig2.js
Original file line number Diff line number Diff line change
Expand Up @@ -1663,13 +1663,13 @@ class SimpleSegmentVisitor {
this.symbols = symbols = {};
}

let inputSymbols = [];
for (let i = 0, ii = referredSegments.length; i < ii; i++) {
const referredSymbols = symbols[referredSegments[i]];
const inputSymbols = [];
for (const referredSegment of referredSegments) {
const referredSymbols = symbols[referredSegment];
// referredSymbols is undefined when we have a reference to a Tables
// segment instead of a SymbolDictionary.
if (referredSymbols) {
inputSymbols = inputSymbols.concat(referredSymbols);
inputSymbols.push(...referredSymbols);
}
}

Expand All @@ -1696,13 +1696,13 @@ class SimpleSegmentVisitor {

// Combines exported symbols from all referred segments
const symbols = this.symbols;
let inputSymbols = [];
for (let i = 0, ii = referredSegments.length; i < ii; i++) {
const referredSymbols = symbols[referredSegments[i]];
const inputSymbols = [];
for (const referredSegment of referredSegments) {
const referredSymbols = symbols[referredSegment];
// referredSymbols is undefined when we have a reference to a Tables
// segment instead of a SymbolDictionary.
if (referredSymbols) {
inputSymbols = inputSymbols.concat(referredSymbols);
inputSymbols.push(...referredSymbols);
}
}
const symbolCodeLength = log2(inputSymbols.length);
Expand Down
5 changes: 1 addition & 4 deletions src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,10 +547,7 @@ function expandBoundsLTR(width, bounds) {
}
}

Array.prototype.splice.apply(
horizon,
[i, j - i + 1].concat(changedHorizon)
);
Array.prototype.splice.apply(horizon, [i, j - i + 1, ...changedHorizon]);
}

// Set new x2 for all unset boundaries.
Expand Down