aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-13 20:24:54 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-02-13 20:50:30 -0500
commit0e6b75438a88456eb0a19bf0fc54bae5d2ec4485 (patch)
tree815ff7f91024ba8a971f63dbf698d411c47ed598
parente3c871bc004d9ca612d908f0f3848cdcfc286cd3 (diff)
Use Map for Translator.tagCache
-rw-r--r--ext/bg/js/translator.js28
1 files changed, 14 insertions, 14 deletions
diff --git a/ext/bg/js/translator.js b/ext/bg/js/translator.js
index 6d5dd50a..3471cb01 100644
--- a/ext/bg/js/translator.js
+++ b/ext/bg/js/translator.js
@@ -27,7 +27,7 @@ class Translator {
constructor() {
this.database = null;
this.deinflector = null;
- this.tagCache = {};
+ this.tagCache = new Map();
}
async prepare() {
@@ -44,12 +44,12 @@ class Translator {
}
async purgeDatabase() {
- this.tagCache = {};
+ this.tagCache.clear();
await this.database.purge();
}
async deleteDictionary(dictionaryName) {
- this.tagCache = {};
+ this.tagCache.clear();
await this.database.deleteDictionary(dictionaryName);
}
@@ -537,22 +537,22 @@ class Translator {
async getTagMetaList(names, title) {
const tagMetaList = [];
- const cache = (
- hasOwn(this.tagCache, title) ?
- this.tagCache[title] :
- (this.tagCache[title] = {})
- );
+ let cache = this.tagCache.get(title);
+ if (typeof cache === 'undefined') {
+ cache = new Map();
+ this.tagCache.set(title, cache);
+ }
for (const name of names) {
const base = Translator.getNameBase(name);
- if (hasOwn(cache, base)) {
- tagMetaList.push(cache[base]);
- } else {
- const tagMeta = await this.database.findTagForTitle(base, title);
- cache[base] = tagMeta;
- tagMetaList.push(tagMeta);
+ let tagMeta = cache.get(base);
+ if (typeof tagMeta === 'undefined') {
+ tagMeta = await this.database.findTagForTitle(base, title);
+ cache.set(base, tagMeta);
}
+
+ tagMetaList.push(tagMeta);
}
return tagMetaList;