Use TimSort (WebKit you lazy fuck)

This commit is contained in:
SukkaW
2024-05-09 10:46:31 +08:00
parent 88201e0125
commit 6a48313ebd
4 changed files with 23 additions and 1 deletions

View File

@@ -0,0 +1,17 @@
import { fetchRemoteTextByLine } from './fetch-text-by-line';
import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
import { processLineFromReadline } from './process-line';
import { sortDomains } from './stable-sort-domain';
import { bench, group, run } from 'mitata';
(async () => {
const data = await processLineFromReadline(await fetchRemoteTextByLine('https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt'));
const gorhill = await getGorhillPublicSuffixPromise();
group('sortDomains', () => {
bench('run', () => sortDomains(data, gorhill));
});
run();
})();

View File

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