mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: 1-pass domain parse
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// tldts-experimental is way faster than tldts, but very little bit inaccurate
|
// tldts-experimental is way faster than tldts, but very little bit inaccurate
|
||||||
// (since it is hashes based). But the result is still deterministic, which is
|
// (since it is hashes based). But the result is still deterministic, which is
|
||||||
// enough when sorting.
|
// enough when sorting.
|
||||||
import { getDomain, getSubdomain } from 'tldts-experimental';
|
import * as tldts from 'tldts-experimental';
|
||||||
import { sort } from './timsort';
|
import { sort } from './timsort';
|
||||||
import { looseTldtsOpt } from '../constants/loose-tldts-opt';
|
import { looseTldtsOpt } from '../constants/loose-tldts-opt';
|
||||||
|
|
||||||
@@ -17,11 +17,10 @@ export const buildParseDomainMap = (inputs: string[]) => {
|
|||||||
for (let i = 0, len = inputs.length; i < len; i++) {
|
for (let i = 0, len = inputs.length; i < len; i++) {
|
||||||
const cur = inputs[i];
|
const cur = inputs[i];
|
||||||
if (!domainMap.has(cur)) {
|
if (!domainMap.has(cur)) {
|
||||||
const topD = getDomain(cur, looseTldtsOpt);
|
const parsed = tldts.parse(cur, looseTldtsOpt);
|
||||||
domainMap.set(cur, topD ?? cur);
|
domainMap.set(cur, parsed.domain ?? cur);
|
||||||
// if (!subdomainMap.has(cur)) {
|
// if (!subdomainMap.has(cur)) {
|
||||||
const subD = getSubdomain(cur, looseTldtsOpt);
|
subdomainMap.set(cur, parsed.subdomain ?? cur);
|
||||||
subdomainMap.set(cur, subD ?? cur);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,10 +44,8 @@ export const sortDomains = (
|
|||||||
const main_domain_a = domainMap.get(a)!;
|
const main_domain_a = domainMap.get(a)!;
|
||||||
const main_domain_b = domainMap.get(b)!;
|
const main_domain_b = domainMap.get(b)!;
|
||||||
|
|
||||||
let t = compare(
|
let t = compare(main_domain_a, main_domain_b)
|
||||||
main_domain_a,
|
|| compare(
|
||||||
main_domain_b
|
|
||||||
) || compare(
|
|
||||||
/** subdomain_a */ subdomainMap.get(a)!,
|
/** subdomain_a */ subdomainMap.get(a)!,
|
||||||
/** subdomain_b */ subdomainMap.get(b)!
|
/** subdomain_b */ subdomainMap.get(b)!
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { getGorhillPublicSuffixPromise } from './get-gorhill-publicsuffix';
|
|||||||
mixedInputs: false
|
mixedInputs: false
|
||||||
};
|
};
|
||||||
|
|
||||||
(['getDomain', 'getPublicSuffix', 'getSubdomain'] as const).forEach(methodName => {
|
(['getDomain', 'getPublicSuffix', 'getSubdomain', 'parse'] as const).forEach(methodName => {
|
||||||
group(methodName, () => {
|
group(methodName, () => {
|
||||||
if (methodName in gorhill) {
|
if (methodName in gorhill) {
|
||||||
bench('gorhill', () => {
|
bench('gorhill', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user