From 019c8cd4d7265012c74bbf4cbee9af7ef3ae310c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 6 Mar 2021 13:04:50 -0500 Subject: Split dictionary order and index sorting (#1491) * Refactor expression comparison * Rename function * Add dictionary index sorting * Update test data --- ext/js/background/backend.js | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'ext/js/background') diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 498b94db..f61e60b6 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -1898,30 +1898,18 @@ class Backend { } _getTranslatorEnabledDictionaryMap(options) { - const dictionaries = []; - const {dictionaries: optionsDictionaries} = options; - for (const title in optionsDictionaries) { - if (!Object.prototype.hasOwnProperty.call(optionsDictionaries, title)) { continue; } - const dictionary = optionsDictionaries[title]; + const enabledDictionaryMap = new Map(); + const {dictionaries} = options; + for (const title in dictionaries) { + if (!Object.prototype.hasOwnProperty.call(dictionaries, title)) { continue; } + const dictionary = dictionaries[title]; if (!dictionary.enabled) { continue; } - dictionaries.push({ - title, - index: dictionaries.length, + enabledDictionaryMap.set(title, { + index: enabledDictionaryMap.size, priority: dictionary.priority, allowSecondarySearches: dictionary.allowSecondarySearches }); } - - dictionaries.sort((v1, v2) => { - const i = v2.priority - v1.priority; - return i !== 0 ? i : v1.index - v2.index; - }); - - const enabledDictionaryMap = new Map(); - for (let i = 0, ii = dictionaries.length; i < ii; ++i) { - const {title, allowSecondarySearches} = dictionaries[i]; - enabledDictionaryMap.set(title, {order: i, allowSecondarySearches}); - } return enabledDictionaryMap; } -- cgit v1.2.3