From 6ffff1093beed5ea57387902f46fb398c48dbb8a Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 22 Jul 2023 21:51:38 +0800 Subject: [PATCH] Perf: make build reject hosts faster --- Build/build-reject-domainset.js | 4 ++-- Build/lib/aho-corasick.js | 23 +++-------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Build/build-reject-domainset.js b/Build/build-reject-domainset.js index 335ccefe..8322331c 100644 --- a/Build/build-reject-domainset.js +++ b/Build/build-reject-domainset.js @@ -141,8 +141,8 @@ const domainSuffixSet = new Set(); }); for await (const line of rl3) { const l = processLine(line); - if (l) { - domainSets.add(l); + if (l && l[0] === '.') { + domainSuffixSet.add(l.slice(1)); } } diff --git a/Build/lib/aho-corasick.js b/Build/lib/aho-corasick.js index c1da8064..5ec4fdaf 100644 --- a/Build/lib/aho-corasick.js +++ b/Build/lib/aho-corasick.js @@ -83,19 +83,9 @@ const createKeywordFilter = (keys) => { } }; - /** - * @param {string} key - */ - const add = (key) => { - const len = key.length; - put(key, len); - build(); - - return true; - }; - - for (let idx = 0; idx < keys.length; idx++) { - add(keys[idx], false); + for (let idx = 0, len = keys.length; idx < len; idx++) { + const key = keys[idx]; + put(key, key.length); } build(); @@ -106,10 +96,6 @@ const createKeywordFilter = (keys) => { */ const search = (text) => { let node = root; - /** @type {string[]} */ - const fText = []; - /** @type {string[]} */ - const oText = []; for (let i = 0, textLen = text.length; i < textLen; i++) { // const key = text.charAt(i); @@ -120,9 +106,6 @@ const createKeywordFilter = (keys) => { } node = node?.children[key] || root; - fText.push(key); - oText.push(key); - if (node.word) { return true; }