Skip to content

Commit

Permalink
Perf: use new hostname trie
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed May 10, 2024
1 parent 59b86f7 commit a486910
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Build/lib/domain-deduper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createTrie } from './trie';
export function domainDeduper(inputDomains: string[], toArray?: true): string[];
export function domainDeduper(inputDomains: string[], toArray: false): Set<string>;
export function domainDeduper(inputDomains: string[], toArray = true): string[] | Set<string> {
const trie = createTrie(inputDomains);
const trie = createTrie(inputDomains, true);
const sets = new Set(inputDomains);

for (let i = 0, len1 = inputDomains.length; i < len1; i++) {
Expand Down
10 changes: 5 additions & 5 deletions Build/lib/stable-sort-domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ const compare = (a: string, b: string) => {
};

export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => {
const domains = inputs.reduce<Map<string, string | null>>((acc, cur) => {
const domains = inputs.reduce<Map<string, string>>((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());

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);
Expand Down

0 comments on commit a486910

Please sign in to comment.