From a486910a26b52ced56b024846eceea2c977b80e6 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 11 May 2024 00:07:43 +0800 Subject: [PATCH] Perf: use new hostname trie --- Build/lib/domain-deduper.ts | 2 +- Build/lib/stable-sort-domain.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Build/lib/domain-deduper.ts b/Build/lib/domain-deduper.ts index 9865ea89..89d34505 100644 --- a/Build/lib/domain-deduper.ts +++ b/Build/lib/domain-deduper.ts @@ -3,7 +3,7 @@ import { createTrie } from './trie'; export function domainDeduper(inputDomains: string[], toArray?: true): string[]; export function domainDeduper(inputDomains: string[], toArray: false): Set; export function domainDeduper(inputDomains: string[], toArray = true): string[] | Set { - const trie = createTrie(inputDomains); + const trie = createTrie(inputDomains, true); const sets = new Set(inputDomains); for (let i = 0, len1 = inputDomains.length; i < len1; i++) { diff --git a/Build/lib/stable-sort-domain.ts b/Build/lib/stable-sort-domain.ts index 2f24c317..2e959517 100644 --- a/Build/lib/stable-sort-domain.ts +++ b/Build/lib/stable-sort-domain.ts @@ -28,10 +28,10 @@ const compare = (a: string, b: string) => { }; export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => { - const domains = inputs.reduce>((acc, cur) => { + const domains = inputs.reduce>((acc, cur) => { if (!acc.has(cur)) { const topD = gorhill.getDomain(cur[0] === '.' ? cur.slice(1) : cur); - acc.set(cur, topD === cur ? null : topD); + acc.set(cur, topD); }; return acc; }, new Map()); @@ -39,10 +39,10 @@ export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => { const sorter = (a: string, b: string) => { if (a === b) return 0; - const $a = domains.get(a); - const $b = domains.get(b); + const $a = domains.get(a)!; + const $b = domains.get(b)!; - if ($a == null || $b == null) { + if ($a === a && $b === b) { return compare(a, b); } return compare($a, $b) || compare(a, b);