mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Use TimSort (WebKit you lazy fuck)
This commit is contained in:
parent
88201e0125
commit
6a48313ebd
17
Build/lib/stable-sort-domain.bench.ts
Normal file
17
Build/lib/stable-sort-domain.bench.ts
Normal 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();
|
||||||
|
})();
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
||||||
|
import { sort } from 'timsort';
|
||||||
|
|
||||||
const compare = (a: string | null, b: string | null) => {
|
const compare = (a: string | null, b: string | null) => {
|
||||||
if (a === b) return 0;
|
if (a === b) return 0;
|
||||||
@ -50,5 +51,7 @@ export const sortDomains = (inputs: string[], gorhill: PublicSuffixList) => {
|
|||||||
return compare($a, $b) || compare(a, b);
|
return compare($a, $b) || compare(a, b);
|
||||||
};
|
};
|
||||||
|
|
||||||
return inputs.sort(sorter);
|
sort(inputs, sorter);
|
||||||
|
|
||||||
|
return inputs;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
"punycode": "^2.3.1",
|
"punycode": "^2.3.1",
|
||||||
"table": "^6.8.2",
|
"table": "^6.8.2",
|
||||||
"tar-stream": "^3.1.7",
|
"tar-stream": "^3.1.7",
|
||||||
|
"timsort": "^0.3.0",
|
||||||
"tldts": "^6.1.19"
|
"tldts": "^6.1.19"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -37,6 +38,7 @@
|
|||||||
"@types/async-retry": "^1.4.8",
|
"@types/async-retry": "^1.4.8",
|
||||||
"@types/bun": "^1.1.1",
|
"@types/bun": "^1.1.1",
|
||||||
"@types/tar-stream": "^3.1.3",
|
"@types/tar-stream": "^3.1.3",
|
||||||
|
"@types/timsort": "^0.3.3",
|
||||||
"bun-types": "^1.1.7",
|
"bun-types": "^1.1.7",
|
||||||
"eslint": "^9.2.0",
|
"eslint": "^9.2.0",
|
||||||
"eslint-config-sukka": "6.0.0-beta.3",
|
"eslint-config-sukka": "6.0.0-beta.3",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user