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:15:24 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-22 14:43:06 -0500
commit69b5007842e08a8fda4016712a5046f81799e638 (patch)
tree85c6407b3be78e36898a38e3f6f1308b9f8f8e9b /ext/bg/js/dictionary.js
parent45c685d00a7b98c33118dc50efd780e5be483936 (diff)
Reduce number of redundant Map.get calls in dictTermsMergeByGloss
Diffstat (limited to 'ext/bg/js/dictionary.js')
-rw-r--r--ext/bg/js/dictionary.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 3a4a58a1..786546ea 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -222,17 +222,34 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
}
if (appendTo === null) {
- // result->expressions[ Expression1[ Reading1[ Tag1, Tag2 ] ], Expression2, ... ]
- if (!result.expressions.has(expression)) {
- result.expressions.set(expression, new Map());
+ /*
+ Data layout:
+ result.expressions = new Map([
+ [expression, new Map([
+ [reading, new Map([
+ [tagName, tagInfo],
+ ...
+ ])],
+ ...
+ ])],
+ ...
+ ]);
+ */
+ let readingMap = result.expressions.get(expression);
+ if (typeof readingMap === 'undefined') {
+ readingMap = new Map();
+ result.expressions.set(expression, readingMap);
}
- if (!result.expressions.get(expression).has(reading)) {
- result.expressions.get(expression).set(reading, []);
+
+ let termTagsMap = readingMap.get(reading);
+ if (typeof termTagsMap === 'undefined') {
+ termTagsMap = new Map();
+ readingMap.set(reading, termTagsMap);
}
for (const tag of definition.termTags) {
- if (!result.expressions.get(expression).get(reading).find((existingTag) => existingTag.name === tag.name)) {
- result.expressions.get(expression).get(reading).push(tag);
+ if (!termTagsMap.has(tag.name)) {
+ termTagsMap.set(tag.name, tag);
}
}
}