mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: domainset class w/o build domain map
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { invariant } from 'foxact/invariant';
|
||||
import createKeywordFilter from '../aho-corasick';
|
||||
import { buildParseDomainMap, sortDomains } from '../stable-sort-domain';
|
||||
import { sortDomains } from '../stable-sort-domain';
|
||||
import { RuleOutput } from './base';
|
||||
import type { SingboxSourceFormat } from '../singbox';
|
||||
|
||||
import * as tldts from 'tldts-experimental';
|
||||
import { looseTldtsOpt } from '../../constants/loose-tldts-opt';
|
||||
|
||||
type Preprocessed = string[];
|
||||
|
||||
export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
@@ -58,18 +61,19 @@ export class DomainsetOutput extends RuleOutput<Preprocessed> {
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
if (!this.apexDomainMap || !this.subDomainMap) {
|
||||
const { domainMap } = buildParseDomainMap(this.$preprocessed);
|
||||
if (!this.apexDomainMap) {
|
||||
const domainMap = new Map<string, string>();
|
||||
|
||||
for (let i = 0, len = this.$preprocessed.length; i < len; i++) {
|
||||
const cur = this.$preprocessed[i];
|
||||
if (!domainMap.has(cur)) {
|
||||
const domain = tldts.getDomain(cur, looseTldtsOpt);
|
||||
domainMap.set(cur, domain ?? cur);
|
||||
}
|
||||
}
|
||||
this.apexDomainMap = domainMap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user