From 749f33737530bffaf30bae48a080fba146137d7e Mon Sep 17 00:00:00 2001 From: Cashew Date: Sun, 14 Jan 2024 12:08:13 +0700 Subject: [PATCH] improve performance --- ext/js/dictionary/dictionary-importer.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/js/dictionary/dictionary-importer.js b/ext/js/dictionary/dictionary-importer.js index 8b20dfee55..110590503b 100644 --- a/ext/js/dictionary/dictionary-importer.js +++ b/ext/js/dictionary/dictionary-importer.js @@ -691,18 +691,19 @@ export class DictionaryImporter { _getArchiveFiles(fileMap, queryDetails) { /** @type {import('dictionary-importer').QueryResult} */ const results = new Map(); + + for (const [fileType] of queryDetails) { + results.set(fileType, []); + } + for (const [fileName, fileEntry] of fileMap.entries()) { for (const [fileType, fileNameFormat] of queryDetails) { - let entries = results.get(fileType); - if (typeof entries === 'undefined') { - entries = []; - results.set(fileType, entries); - } + if (!fileNameFormat.test(fileName)) { continue; } + const entries = results.get(fileType); - if (fileNameFormat.test(fileName)) { - entries.push(fileEntry); - break; - } + // @ts-expect-error - entries should be initialized + entries.push(fileEntry); + break; } } return results;