From 19fb7dacb4c951906c5ce3094711f436b0e06c02 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 15 Feb 2020 17:23:29 -0500 Subject: [PATCH] Assign result properties to variables to reduce number of lookups --- ext/bg/js/dictionary.js | 26 ++++++++++++++++---------- 1 file 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); } }