mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Replace sortDomains w/ trie dump sort
This commit is contained in:
@@ -88,14 +88,6 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected apexDomainMap: Map<string, string> | null = null;
|
||||
protected subDomainMap: Map<string, string> | null = null;
|
||||
withDomainMap(apexDomainMap: Map<string, string>, subDomainMap: Map<string, string>) {
|
||||
this.apexDomainMap = apexDomainMap;
|
||||
this.subDomainMap = subDomainMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
addDomain(domain: string) {
|
||||
this.domainTrie.add(domain);
|
||||
return this;
|
||||
|
||||
@@ -20,13 +20,8 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
return;
|
||||
}
|
||||
results.push(domain);
|
||||
});
|
||||
}, true);
|
||||
|
||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||
const { domainMap, subdomainMap } = buildParseDomainMap(results);
|
||||
this.apexDomainMap = domainMap;
|
||||
this.subDomainMap = subdomainMap;
|
||||
}
|
||||
const sorted = results;
|
||||
sorted.push('this_ruleset_is_made_by_sukkaw.ruleset.skk.moe');
|
||||
|
||||
@@ -63,9 +58,21 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
} satisfies SingboxSourceFormat);
|
||||
}
|
||||
|
||||
protected apexDomainMap: Map<string, string> | null = null;
|
||||
protected subDomainMap: Map<string, string> | null = null;
|
||||
withDomainMap(apexDomainMap: Map<string, string>, subDomainMap: Map<string, string>) {
|
||||
this.apexDomainMap = apexDomainMap;
|
||||
this.subDomainMap = subDomainMap;
|
||||
return this;
|
||||
}
|
||||
|
||||
getStatMap() {
|
||||
invariant(this.$preprocessed, 'Non dumped yet');
|
||||
invariant(this.apexDomainMap, 'Missing apex domain map');
|
||||
|
||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||
const { domainMap } = buildParseDomainMap(this.$preprocessed);
|
||||
this.apexDomainMap = domainMap;
|
||||
}
|
||||
|
||||
return Array.from(this.$preprocessed
|
||||
.reduce<Map<string, number>>(
|
||||
|
||||
@@ -4,7 +4,6 @@ import createKeywordFilter from '../aho-corasick';
|
||||
import { appendArrayInPlace } from '../append-array-in-place';
|
||||
import { appendArrayFromSet } from '../misc';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
import { sortDomains } from '../stable-sort-domain';
|
||||
import { RuleOutput } from './base';
|
||||
import picocolors from 'picocolors';
|
||||
import { normalizeDomain } from '../normalize-domain';
|
||||
@@ -24,9 +23,9 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
||||
const domainSuffixes: string[] = [];
|
||||
const sortedDomainRules: string[] = [];
|
||||
|
||||
for (const domain of sortDomains(this.domainTrie.dump(), this.apexDomainMap, this.subDomainMap)) {
|
||||
this.domainTrie.dump((domain) => {
|
||||
if (kwfilter(domain)) {
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
if (domain[0] === '.') {
|
||||
domainSuffixes.push(domain.slice(1));
|
||||
@@ -35,7 +34,7 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
|
||||
domains.push(domain);
|
||||
sortedDomainRules.push(`DOMAIN,${domain}`);
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
|
||||
return [domains, domainSuffixes, sortedDomainRules] satisfies Preprocessed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user