Perf: new timsort

This commit is contained in:
SukkaW
2024-05-10 22:54:49 +08:00
parent deb3688245
commit 487d4fecd6
4 changed files with 958 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
import { sort } from 'timsort';
import { sort } from './timsort';
const compare = (a: string, b: string) => {
if (a === b) return 0;
@@ -42,10 +42,10 @@ export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => {
const $a = domains.get(a);
const $b = domains.get(b);
if ($a && $b) {
return compare($a, $b) || compare(a, b);
if ($a == null || $b == null) {
return compare(a, b);
}
return compare(a, b);
return compare($a, $b) || compare(a, b);
};
sort(inputs, sorter);