Skip to content

Commit 45de73b

Browse files
Merge pull request #15059 from Snuffleupagus/rm-some-concat
Reduce unnecessary usage of `Array.prototype.concat()`
2 parents f516bb2 + c21f4fa commit 45de73b

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

external/builder/preprocessor2.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ function postprocessNode(ctx, node) {
220220
case "BlockStatement":
221221
// Block statements inside a block are moved to the parent one.
222222
const subChildren = node.body[subExpressionIndex].body;
223-
Array.prototype.splice.apply(
224-
node.body,
225-
[subExpressionIndex, 1].concat(subChildren)
226-
);
223+
Array.prototype.splice.apply(node.body, [
224+
subExpressionIndex,
225+
1,
226+
...subChildren,
227+
]);
227228
subExpressionIndex += Math.max(subChildren.length - 1, 0);
228229
continue;
229230
case "ReturnStatement":

src/core/cff_parser.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ class CFFCompiler {
13871387
const output = {
13881388
data: [],
13891389
length: 0,
1390-
add: function CFFCompiler_add(data) {
1390+
add(data) {
13911391
this.data = this.data.concat(data);
13921392
this.length = this.data.length;
13931393
},
@@ -1680,7 +1680,7 @@ class CFFCompiler {
16801680
}
16811681

16821682
compileDict(dict, offsetTracker) {
1683-
let out = [];
1683+
const out = [];
16841684
// The dictionary keys must be in a certain order.
16851685
const order = dict.order;
16861686
for (let i = 0; i < order.length; ++i) {
@@ -1708,7 +1708,7 @@ class CFFCompiler {
17081708
switch (type) {
17091709
case "num":
17101710
case "sid":
1711-
out = out.concat(this.encodeNumber(value));
1711+
out.push(...this.encodeNumber(value));
17121712
break;
17131713
case "offset":
17141714
// For offsets we just insert a 32bit integer so we don't have to
@@ -1720,20 +1720,20 @@ class CFFCompiler {
17201720
if (!offsetTracker.isTracking(name)) {
17211721
offsetTracker.track(name, out.length);
17221722
}
1723-
out = out.concat([0x1d, 0, 0, 0, 0]);
1723+
out.push(0x1d, 0, 0, 0, 0);
17241724
break;
17251725
case "array":
17261726
case "delta":
1727-
out = out.concat(this.encodeNumber(value));
1727+
out.push(...this.encodeNumber(value));
17281728
for (let k = 1, kk = values.length; k < kk; ++k) {
1729-
out = out.concat(this.encodeNumber(values[k]));
1729+
out.push(...this.encodeNumber(values[k]));
17301730
}
17311731
break;
17321732
default:
17331733
throw new FormatError(`Unknown data type of ${type}`);
17341734
}
17351735
}
1736-
out = out.concat(dict.opcodes[key]);
1736+
out.push(...dict.opcodes[key]);
17371737
}
17381738
return out;
17391739
}

src/core/jbig2.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1663,13 +1663,13 @@ class SimpleSegmentVisitor {
16631663
this.symbols = symbols = {};
16641664
}
16651665

1666-
let inputSymbols = [];
1667-
for (let i = 0, ii = referredSegments.length; i < ii; i++) {
1668-
const referredSymbols = symbols[referredSegments[i]];
1666+
const inputSymbols = [];
1667+
for (const referredSegment of referredSegments) {
1668+
const referredSymbols = symbols[referredSegment];
16691669
// referredSymbols is undefined when we have a reference to a Tables
16701670
// segment instead of a SymbolDictionary.
16711671
if (referredSymbols) {
1672-
inputSymbols = inputSymbols.concat(referredSymbols);
1672+
inputSymbols.push(...referredSymbols);
16731673
}
16741674
}
16751675

@@ -1696,13 +1696,13 @@ class SimpleSegmentVisitor {
16961696

16971697
// Combines exported symbols from all referred segments
16981698
const symbols = this.symbols;
1699-
let inputSymbols = [];
1700-
for (let i = 0, ii = referredSegments.length; i < ii; i++) {
1701-
const referredSymbols = symbols[referredSegments[i]];
1699+
const inputSymbols = [];
1700+
for (const referredSegment of referredSegments) {
1701+
const referredSymbols = symbols[referredSegment];
17021702
// referredSymbols is undefined when we have a reference to a Tables
17031703
// segment instead of a SymbolDictionary.
17041704
if (referredSymbols) {
1705-
inputSymbols = inputSymbols.concat(referredSymbols);
1705+
inputSymbols.push(...referredSymbols);
17061706
}
17071707
}
17081708
const symbolCodeLength = log2(inputSymbols.length);

src/display/text_layer.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -547,10 +547,7 @@ function expandBoundsLTR(width, bounds) {
547547
}
548548
}
549549

550-
Array.prototype.splice.apply(
551-
horizon,
552-
[i, j - i + 1].concat(changedHorizon)
553-
);
550+
Array.prototype.splice.apply(horizon, [i, j - i + 1, ...changedHorizon]);
554551
}
555552

556553
// Set new x2 for all unset boundaries.

0 commit comments

Comments
 (0)