Perf: refactor trie to avoid iterate twice

This commit is contained in:
SukkaW
2024-09-07 00:16:56 +08:00
parent 315b38b999
commit 8bcfc0e528
8 changed files with 191 additions and 197 deletions

View File

@@ -5,11 +5,11 @@ export function domainDeduper(inputDomains: string[] | Trie, toArray: false): Se
export function domainDeduper(inputDomains: string[] | Trie, toArray = true): string[] | Set<string> {
let trie: Trie;
if (Array.isArray(inputDomains)) {
trie = createTrie(inputDomains, true, true);
} else if (!inputDomains.hostnameMode || !inputDomains.smolTree) {
throw new Error('Invalid trie');
} else {
trie = createTrie(inputDomains, true);
} else if (inputDomains.smolTree) {
trie = inputDomains;
} else {
throw new Error('Invalid trie');
}
const dumped = trie.dump();