summaryrefslogtreecommitdiff
path: root/ext/bg
diff options
context:
space:
mode:
Diffstat (limited to 'ext/bg')
-rw-r--r--ext/bg/js/dictionary.js43
-rw-r--r--ext/bg/js/util.js26
2 files changed, 33 insertions, 36 deletions
diff --git a/ext/bg/js/dictionary.js b/ext/bg/js/dictionary.js
index 1bc3c93c..bffa7afa 100644
--- a/ext/bg/js/dictionary.js
+++ b/ext/bg/js/dictionary.js
@@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/*global utilSetEqual, utilSetIntersection, apiTemplateRender*/
+/*global apiTemplateRender*/
function dictEnabledSet(options) {
const enabledDictionaryMap = new Map();
@@ -145,6 +145,30 @@ function dictTermsGroup(definitions, dictionaries) {
return dictTermsSort(results);
}
+function dictAreSetsEqual(set1, set2) {
+ if (set1.size !== set2.size) {
+ return false;
+ }
+
+ for (const value of set1) {
+ if (!set2.has(value)) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function dictGetSetIntersection(set1, set2) {
+ const result = [];
+ for (const value of set1) {
+ if (set2.has(value)) {
+ result.push(value);
+ }
+ }
+ return result;
+}
+
function dictTermsMergeBySequence(definitions, mainDictionary) {
const sequencedDefinitions = new Map();
const nonSequencedDefinitions = [];
@@ -262,16 +286,15 @@ function dictTermsMergeByGloss(result, definitions, appendTo=null, mergedIndices
}
for (const definition of definitionsByGloss.values()) {
- definition.only = [];
- if (!utilSetEqual(definition.expression, resultExpressionSet)) {
- for (const expression of utilSetIntersection(definition.expression, resultExpressionSet)) {
- definition.only.push(expression);
- }
+ const only = [];
+ const expressionSet = definition.expression;
+ const readingSet = definition.reading;
+ definition.only = only;
+ if (!dictAreSetsEqual(expressionSet, resultExpressionSet)) {
+ only.push(...dictGetSetIntersection(expressionSet, resultExpressionSet));
}
- if (!utilSetEqual(definition.reading, resultReadingSet)) {
- for (const reading of utilSetIntersection(definition.reading, resultReadingSet)) {
- definition.only.push(reading);
- }
+ if (!dictAreSetsEqual(readingSet, resultReadingSet)) {
+ only.push(...dictGetSetIntersection(readingSet, resultReadingSet));
}
}
diff --git a/ext/bg/js/util.js b/ext/bg/js/util.js
index 333e814b..9ebd2ac4 100644
--- a/ext/bg/js/util.js
+++ b/ext/bg/js/util.js
@@ -59,32 +59,6 @@ function utilBackgroundFunctionIsolate(func) {
return backgroundPage.utilFunctionIsolate(func);
}
-function utilSetEqual(setA, setB) {
- if (setA.size !== setB.size) {
- return false;
- }
-
- for (const value of setA) {
- if (!setB.has(value)) {
- return false;
- }
- }
-
- return true;
-}
-
-function utilSetIntersection(setA, setB) {
- return new Set(
- [...setA].filter((value) => setB.has(value))
- );
-}
-
-function utilSetDifference(setA, setB) {
- return new Set(
- [...setA].filter((value) => !setB.has(value))
- );
-}
-
function utilStringHashCode(string) {
let hashCode = 0;