mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: re-use trie when building reject domainsets
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import { createTrie } from './trie';
|
||||
import { createTrie, type Trie } from './trie';
|
||||
|
||||
export function domainDeduper(inputDomains: string[] | Trie, toArray?: true): string[];
|
||||
export function domainDeduper(inputDomains: string[] | Trie, toArray: false): Set<string>;
|
||||
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 = inputDomains;
|
||||
}
|
||||
|
||||
export function domainDeduper(inputDomains: string[], toArray?: true): string[];
|
||||
export function domainDeduper(inputDomains: string[], toArray: false): Set<string>;
|
||||
export function domainDeduper(inputDomains: string[], toArray = true): string[] | Set<string> {
|
||||
const trie = createTrie(inputDomains, true, true);
|
||||
const dumped = trie.dump();
|
||||
if (toArray) {
|
||||
return dumped;
|
||||
|
||||
Reference in New Issue
Block a user