mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-13 01:30:37 +08:00
Perf: make trie.add faster
This commit is contained in:
parent
6031d9652e
commit
a0c8751cb2
@ -30,25 +30,13 @@ const createNode = (parent: TrieNode | null = null): TrieNode => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const hostnameToTokens = (hostname: string): string[] => {
|
const hostnameToTokens = (hostname: string): string[] => {
|
||||||
let buf = '';
|
return hostname.split('.').reduce<string[]>((acc, token, index) => {
|
||||||
const tokens: string[] = [];
|
if (index !== 0) {
|
||||||
for (let i = 0, l = hostname.length; i < l; i++) {
|
acc.push('.');
|
||||||
const c = hostname[i];
|
|
||||||
if (c === '.') {
|
|
||||||
if (buf) {
|
|
||||||
tokens.push(buf, /* . */ c);
|
|
||||||
buf = '';
|
|
||||||
} else {
|
|
||||||
tokens.push(/* . */ c);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buf += c;
|
|
||||||
}
|
}
|
||||||
}
|
acc.push(token);
|
||||||
if (buf) {
|
return acc;
|
||||||
tokens.push(buf);
|
}, []);
|
||||||
}
|
|
||||||
return tokens;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createTrie = (from?: string[] | Set<string> | null, hostnameMode = false, smolTree = false) => {
|
export const createTrie = (from?: string[] | Set<string> | null, hostnameMode = false, smolTree = false) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user