aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/translator.js
diff options
context:
space:
mode:
authorAlex Yatskov <FooSoft@users.noreply.github.com>2019-09-05 19:46:14 -0700
committerGitHub <noreply@github.com>2019-09-05 19:46:14 -0700
commit6dc44e3f33d6f2ac2b5b7442879631a2943fcadc (patch)
treeeaac78e153efeb2a4496bd14f0c18a5d11d61d24 /ext/bg/js/translator.js
parent9cd0101b62fe99d736b4e6b9072c2aa4827311af (diff)
parentb90dea0e6dd9e8321ca616f256d8d88fb3c599d1 (diff)
Merge pull request #202 from toasted-nutbread/temporary-object-optimization
Temporary object optimization
Diffstat (limited to 'ext/bg/js/translator.js')
-rw-r--r--ext/bg/js/translator.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index c6af1f4e..c89b43ff 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -186,7 +186,7 @@ class Translator {
let deinflections = await this.findTermDeinflections(text, titles, cache);
const textHiragana = jpKatakanaToHiragana(text);
if (text !== textHiragana) {
- deinflections = deinflections.concat(await this.findTermDeinflections(textHiragana, titles, cache));
+ deinflections.push(...await this.findTermDeinflections(textHiragana, titles, cache));
}
let definitions = [];
@@ -235,7 +235,7 @@ class Translator {
let deinflections = [];
for (let i = text.length; i > 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;
@@ -247,7 +247,7 @@ class Translator {
const titles = Object.keys(dictionaries);
for (const c of text) {
if (!processed[c]) {
- definitions = definitions.concat(await this.database.findKanji(c, titles));
+ definitions.push(...await this.database.findKanji(c, titles));
processed[c] = true;
}
}
@@ -277,7 +277,7 @@ class Translator {
async buildTermFrequencies(definition, titles) {
let terms = [];
if (definition.expressions) {
- terms = terms.concat(definition.expressions);
+ terms.push(...definition.expressions);
} else {
terms.push(definition);
}
@@ -299,7 +299,7 @@ class Translator {
async expandTags(names, title) {
const tags = [];
for (const name of names) {
- const base = name.split(':')[0];
+ const base = Translator.getNameBase(name);
const meta = await this.database.findTagForTitle(base, title);
const tag = {name};
@@ -318,7 +318,7 @@ class Translator {
async expandStats(items, title) {
const stats = {};
for (const name in items) {
- const base = name.split(':')[0];
+ const base = Translator.getNameBase(name);
const meta = await this.database.findTagForTitle(base, title);
const group = stats[meta.category] = stats[meta.category] || [];
@@ -346,4 +346,9 @@ class Translator {
return stats;
}
+
+ static getNameBase(name) {
+ const pos = name.indexOf(':');
+ return (pos >= 0 ? name.substr(0, pos) : name);
+ }
}