mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +08:00
Perf: slightly improve trie.whitelist performance
This commit is contained in:
parent
5d0a974b7f
commit
274c2453e2
@ -328,12 +328,16 @@ abstract class Triebase<Meta = any> {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
public dumpWithMeta() {
|
public dumpWithMeta(onSuffix: (suffix: string, meta: Meta | undefined) => void): void;
|
||||||
const results: Array<[string, Meta]> = [];
|
public dumpWithMeta(): string[];
|
||||||
|
public dumpWithMeta(onSuffix?: (suffix: string, meta: Meta | undefined) => void): string[] | void {
|
||||||
|
const results: string[] = [];
|
||||||
|
|
||||||
this.walk((suffix, meta) => {
|
const handleSuffix = onSuffix
|
||||||
results.push([fastStringArrayJoin(suffix, ''), meta]);
|
? (suffix: string[], meta: Meta | undefined) => onSuffix(fastStringArrayJoin(suffix, ''), meta)
|
||||||
});
|
: (suffix: string[]) => results.push(fastStringArrayJoin(suffix, ''));
|
||||||
|
|
||||||
|
this.walk(handleSuffix);
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
@ -417,13 +421,13 @@ export class HostnameSmolTrie<Meta = any> extends Triebase<Meta> {
|
|||||||
// Removing all the child nodes by empty the children
|
// Removing all the child nodes by empty the children
|
||||||
// This removes the only child ".", which removes "blog.sub.example.com"
|
// This removes the only child ".", which removes "blog.sub.example.com"
|
||||||
parent[2].clear();
|
parent[2].clear();
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Trying to whitelist `example.com` when there is already a `.example.com` in the trie
|
// Trying to whitelist `example.com` when there is already a `.example.com` in the trie
|
||||||
const dotNode = node[2].get('.');
|
const dotNode = node[2].get('.');
|
||||||
if (dotNode) {
|
if (dotNode) {
|
||||||
dotNode[0] = false;
|
dotNode[0] = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// return early if not found
|
// return early if not found
|
||||||
if (!node[0]) return;
|
if (!node[0]) return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user