mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Reduce unnecessary usage of Array.prototype.concat()
There are obviously cases where using `concat` makes perfect sense, since that method doesn't change any of the existing Arrays; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat However, in a few cases throughout the code-base that's not an issue and using `concat` only leads to unnecessary intermediate allocations. With modern JavaScript we can thus replace those with a combination of `push` and spread-syntax, which wasn't originally possible when the code was written.
This commit is contained in:
parent
f516bb2174
commit
c21f4faaf8
4 changed files with 21 additions and 23 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue