浏览代码

Chore: minor changes

SukkaW 1 年之前
父节点
当前提交
20edd90c9b
共有 2 个文件被更改,包括 11 次插入6 次删除
  1. 1 1
      Build/build-internal-reverse-chn-cidr.ts
  2. 10 5
      Build/lib/trie.ts

+ 1 - 1
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<string[]> {
       // TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956

+ 10 - 5
Build/lib/trie.ts

@@ -603,20 +603,25 @@ export class HostnameSmolTrie<Meta = unknown> extends Triebase<Meta> {
       node[0] = deleteBit(node[0], START);
     }
 
-    cleanUpEmptyNode(node);
+    cleanUpEmptyTrailNode(node);
   };
 }
 
-function cleanUpEmptyNode(node: TrieNode<unknown>) {
+function cleanUpEmptyTrailNode(node: TrieNode<unknown>) {
   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]);
   }
 }