Perf: make domain sorting faster

This commit is contained in:
SukkaW 2024-05-26 04:17:02 +08:00
parent 0d3148fb2a
commit db6786a0d6

View File

@ -3,15 +3,16 @@ import { sort } from './timsort';
export const compare = (a: string, b: string) => { export const compare = (a: string, b: string) => {
if (a === b) return 0; if (a === b) return 0;
return (a.length - b.length) || a.localeCompare(b);
const aLen = a.length;
const r = aLen - b.length;
if (r !== 0) return r;
return a.localeCompare(b);
}; };
const tldtsOpt = { allowPrivateDomains: false, detectIp: false, validateHostname: false }; const tldtsOpt = {
extractHostname: false,
allowPrivateDomains: false,
detectIp: false,
validateHostname: false,
mixedInputs: false
};
export const sortDomains = (inputs: string[]) => { export const sortDomains = (inputs: string[]) => {
const domainMap = new Map<string, string>(); const domainMap = new Map<string, string>();