summaryrefslogtreecommitdiff
path: root/ext/bg/js/dictionary.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-15 17:23:29 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 14:43:06 -0500
commit19fb7dacb4c951906c5ce3094711f436b0e06c02 (patch)
tree4f944360f90e8e56832e5113474028355988fefa /ext/bg/js/dictionary.js
parent69b5007842e08a8fda4016712a5046f81799e638 (diff)
Assign result properties to variables to reduce number of lookups
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js26
1 files changed, 16 insertions, 10 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 786546ea..1bc3c93c 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -177,11 +177,17 @@ function dictTermsMergeBySequence(definitions, mainDictionary) {
function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices=null) {
const definitionsByGloss = appendTo !== null ? appendTo : new Map();
+
+ const resultExpressionsMap = result.expressions;
+ const resultExpressionSet = result.expression;
+ const resultReadingSet = result.reading;
+ const resultSource = result.source;
+
for (const [index, definition] of definitions.entries()) {
const {expression, reading} = definition;
if (mergedIndices !== null) {
- const expressionMap = result.expressions.get(expression);
+ const expressionMap = resultExpressionsMap.get(expression);
if (
typeof expressionMap !== 'undefined' &&
typeof expressionMap.get(reading) !== 'undefined'
@@ -200,7 +206,7 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
reading: new Set(),
definitionTags: [],
glossary: definition.glossary,
- source: result.source,
+ source: resultSource,
reasons: [],
score: definition.score,
id: definition.id,
@@ -212,8 +218,8 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
glossDefinition.expression.add(expression);
glossDefinition.reading.add(reading);
- result.expression.add(expression);
- result.reading.add(reading);
+ resultExpressionSet.add(expression);
+ resultReadingSet.add(reading);
for (const tag of definition.definitionTags) {
if (!glossDefinition.definitionTags.find((existingTag) => existingTag.name === tag.name)) {
@@ -235,10 +241,10 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
...
]);
*/
- let readingMap = result.expressions.get(expression);
+ let readingMap = resultExpressionsMap.get(expression);
if (typeof readingMap === 'undefined') {
readingMap = new Map();
- result.expressions.set(expression, readingMap);
+ resultExpressionsMap.set(expression, readingMap);
}
let termTagsMap = readingMap.get(reading);
@@ -257,13 +263,13 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
for (const definition of definitionsByGloss.values()) {
definition.only = [];
- if (!utilSetEqual(definition.expression, result.expression)) {
- for (const expression of utilSetIntersection(definition.expression, result.expression)) {
+ if (!utilSetEqual(definition.expression, resultExpressionSet)) {
+ for (const expression of utilSetIntersection(definition.expression, resultExpressionSet)) {
definition.only.push(expression);
}
}
- if (!utilSetEqual(definition.reading, result.reading)) {
- for (const reading of utilSetIntersection(definition.reading, result.reading)) {
+ if (!utilSetEqual(definition.reading, resultReadingSet)) {
+ for (const reading of utilSetIntersection(definition.reading, resultReadingSet)) {
definition.only.push(reading);
}
}