Replace some instances of Array.concat

.push or .unshift can accomplish the same operation without constructing new arrays.
This commit is contained in:
toasted-nutbread 2019-08-11 14:59:02 -04:00
parent 4ac55da7dd
commit fc4a961412
3 changed files with 12 additions and 11 deletions

View File

@ -140,16 +140,17 @@ function dictTermsCompressTags(definitions) {
function dictTermsGroup(definitions, dictionaries) { function dictTermsGroup(definitions, dictionaries) {
const groups = {}; const groups = {};
for (const definition of definitions) { for (const definition of definitions) {
const key = [definition.source, definition.expression].concat(definition.reasons); const key = [definition.source, definition.expression];
key.push(...definition.reasons);
if (definition.reading) { if (definition.reading) {
key.push(definition.reading); key.push(definition.reading);
} }
const group = groups[key]; const keyString = key.toString();
if (group) { if (groups.hasOwnProperty(keyString)) {
group.push(definition); groups[keyString].push(definition);
} else { } else {
groups[key] = [definition]; groups[keyString] = [definition];
} }
} }

View File

@ -186,7 +186,7 @@ class Translator {
let deinflections = await this.findTermDeinflections(text, titles, cache); let deinflections = await this.findTermDeinflections(text, titles, cache);
const textHiragana = jpKatakanaToHiragana(text); const textHiragana = jpKatakanaToHiragana(text);
if (text !== textHiragana) { if (text !== textHiragana) {
deinflections = deinflections.concat(await this.findTermDeinflections(textHiragana, titles, cache)); deinflections.push(...await this.findTermDeinflections(textHiragana, titles, cache));
} }
let definitions = []; let definitions = [];
@ -235,7 +235,7 @@ class Translator {
let deinflections = []; let deinflections = [];
for (let i = text.length; i > 0; --i) { for (let i = text.length; i > 0; --i) {
const textSlice = text.slice(0, i); const textSlice = text.slice(0, i);
deinflections = deinflections.concat(await this.deinflector.deinflect(textSlice, definer)); deinflections.push(...await this.deinflector.deinflect(textSlice, definer));
} }
return deinflections; return deinflections;
@ -247,7 +247,7 @@ class Translator {
const titles = Object.keys(dictionaries); const titles = Object.keys(dictionaries);
for (const c of text) { for (const c of text) {
if (!processed[c]) { if (!processed[c]) {
definitions = definitions.concat(await this.database.findKanji(c, titles)); definitions.push(...await this.database.findKanji(c, titles));
processed[c] = true; processed[c] = true;
} }
} }
@ -277,7 +277,7 @@ class Translator {
async buildTermFrequencies(definition, titles) { async buildTermFrequencies(definition, titles) {
let terms = []; let terms = [];
if (definition.expressions) { if (definition.expressions) {
terms = terms.concat(definition.expressions); terms.push(...definition.expressions);
} else { } else {
terms.push(definition); terms.push(definition);
} }

View File

@ -152,7 +152,7 @@ function docSentenceExtract(source, extent) {
if (quoteStack.length > 0 && c === quoteStack[0]) { if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop(); quoteStack.pop();
} else if (c in quotesBwd) { } else if (c in quotesBwd) {
quoteStack = [quotesBwd[c]].concat(quoteStack); quoteStack.unshift(quotesBwd[c]);
} }
} }
@ -181,7 +181,7 @@ function docSentenceExtract(source, extent) {
if (quoteStack.length > 0 && c === quoteStack[0]) { if (quoteStack.length > 0 && c === quoteStack[0]) {
quoteStack.pop(); quoteStack.pop();
} else if (c in quotesFwd) { } else if (c in quotesFwd) {
quoteStack = [quotesFwd[c]].concat(quoteStack); quoteStack.unshift(quotesFwd[c]);
} }
} }