From 20edd90c9be088983b431b0ec1131ed42ae111a7 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 2 Mar 2025 19:58:37 +0800 Subject: [PATCH] Chore: minor changes --- Build/build-internal-reverse-chn-cidr.ts | 2 +- Build/lib/trie.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Build/build-internal-reverse-chn-cidr.ts b/Build/build-internal-reverse-chn-cidr.ts index b46d11c5..1bd40517 100644 --- a/Build/build-internal-reverse-chn-cidr.ts +++ b/Build/build-internal-reverse-chn-cidr.ts @@ -18,7 +18,7 @@ const pool = new Worktank({ warmup: true, autoterminate: 30000, // The interval of milliseconds at which to check if the pool can be automatically terminated, to free up resources, workers will be spawned up again if needed env: {}, - methods: { // An object mapping function names to functions objects to serialize and deserialize into each worker thread, only functions that don't depend on their closure can be serialized + methods: { // eslint-disable-next-line object-shorthand -- workertank getreversedCidr: async function (cidr: string[], importMetaUrl: string): Promise { // TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956 diff --git a/Build/lib/trie.ts b/Build/lib/trie.ts index 5ce5a8e1..2a73a4a9 100644 --- a/Build/lib/trie.ts +++ b/Build/lib/trie.ts @@ -603,20 +603,25 @@ export class HostnameSmolTrie extends Triebase { node[0] = deleteBit(node[0], START); } - cleanUpEmptyNode(node); + cleanUpEmptyTrailNode(node); }; } -function cleanUpEmptyNode(node: TrieNode) { +function cleanUpEmptyTrailNode(node: TrieNode) { if ( + // the current node is not an "end node", a.k.a. not the start of a domain missingBit(node[0], START) - && node[2].size === 0 + // also no leading "." (no subdomain) && missingBit(node[0], INCLUDE_ALL_SUBDOMAIN) + // child is empty + && node[2].size === 0 + // has parent: we need to detele the cureent node from the parent + // we also need to recursively clean up the parent node && node[1] ) { node[1][2].delete(node[3]); - - cleanUpEmptyNode(node[1]); + // finish of the current stack + return cleanUpEmptyTrailNode(node[1]); } }