mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: faster trie by reducing new object creation
This commit is contained in:
@@ -107,16 +107,11 @@ export const createTrie = (from?: string[] | Set<string> | null, hostnameMode =
|
|||||||
// Make sure parent `[start]sub.example.com` (without dot) is removed (SETINEL to false)
|
// Make sure parent `[start]sub.example.com` (without dot) is removed (SETINEL to false)
|
||||||
parent[SENTINEL] = false;
|
parent[SENTINEL] = false;
|
||||||
|
|
||||||
// Removing the rest of the parent's child nodes by disconnecting the old one and creating a new node
|
// Removing the rest of the parent's child nodes
|
||||||
const newNode = createNode(node);
|
node.clear();
|
||||||
// The SENTINEL of this newNode will be set to true at the end of the function, so we don't need to set it here
|
// The SENTINEL of this node will be set to true at the end of the function, so we don't need to set it here
|
||||||
|
|
||||||
parent.set('.', newNode);
|
// we can use else-if here, because new node is empty, we don't need to check the leading "."
|
||||||
|
|
||||||
// Now the real leaf-est node is the new node, change the pointer to it
|
|
||||||
node = newNode;
|
|
||||||
|
|
||||||
// we can use else-if here, because new node is empty, so we don't need to check the leading "."
|
|
||||||
} else if (node.get('.')?.[SENTINEL] === true) {
|
} else if (node.get('.')?.[SENTINEL] === true) {
|
||||||
// Trying to add `example.com` when there is already a `.example.com` in the trie
|
// Trying to add `example.com` when there is already a `.example.com` in the trie
|
||||||
// No need to increment size and set SENTINEL to true (skip this "new" item)
|
// No need to increment size and set SENTINEL to true (skip this "new" item)
|
||||||
|
|||||||
Reference in New Issue
Block a user