Perf: many changes

- Hoist process hosts line callback
- Reduce dp hosts file size
- Reduce domain sort
This commit is contained in:
SukkaW
2024-05-02 08:13:15 +08:00
parent 10bde9f1e8
commit e5d511d105
6 changed files with 42 additions and 35 deletions

View File

@@ -42,7 +42,15 @@ export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => {
const sorter = (a: string, b: string) => {
if (a === b) return 0;
return compare(domains.get(a)!, domains.get(b)!) || compare(a, b);
const $a = domains.get(a)!;
const $b = domains.get(b)!;
// avoid compare same thing twice
if (a === $a && b === $b) {
return compare(a, b);
}
return compare($a, $b) || compare(a, b);
};
return inputs.sort(sorter);