Minor Changes + Housekeeping

This commit is contained in:
SukkaW
2024-07-02 10:50:09 +08:00
parent b325f31990
commit dda0555c0b
8 changed files with 34 additions and 67 deletions

View File

@@ -13,35 +13,6 @@ const createNode = (): Node => {
return node;
};
const deepNodeToJSON = (node: Node, wset: WeakSet<Node>) => {
if (wset.has(node)) {
return 'circular';
}
wset.add(node);
const obj: Record<string, any> = {};
if (node[WORDEND]) {
obj['[end]'] = node[WORDEND];
}
node.forEach((value, key) => {
obj[key] = deepNodeToJSON(value, wset);
});
return obj;
};
function createNodeInspectCustom(node: Node) {
const wset = new WeakSet<Node>();
return () => {
try {
return JSON.stringify(deepNodeToJSON(node, wset), null, 2);
} catch (e) {
console.error(e);
return '';
}
};
}
const createKeywordFilter = (keys: string[] | Set<string>) => {
const root = createNode();
@@ -92,7 +63,7 @@ const createKeywordFilter = (keys: string[] | Set<string>) => {
// };
// build();
const tester = (text: string) => {
return (text: string) => {
let node: Node | undefined = root;
for (let i = 0, textLen = text.length; i < textLen; i++) {
@@ -111,10 +82,6 @@ const createKeywordFilter = (keys: string[] | Set<string>) => {
return false;
};
tester[Bun.inspect.custom] = createNodeInspectCustom(root);
return tester;
};
export default createKeywordFilter;

View File

@@ -159,7 +159,7 @@ const MARK = 'this_ruleset_is_made_by_sukkaw.ruleset.skk.moe';
export const createRuleset = (
parentSpan: Span,
title: string, description: string[] | readonly string[], date: Date, content: string[],
type: 'ruleset' | 'domainset', surgePath: string, clashPath: string
type: ('ruleset' | 'domainset' | string & {}), surgePath: string, clashPath: string
) => parentSpan.traceChild(`create ruleset: ${path.basename(surgePath, path.extname(surgePath))}`).traceAsyncFn((childSpan) => {
const surgeContent = withBannerArray(
title, description, date,
@@ -177,7 +177,7 @@ export const createRuleset = (
_clashContent = [`DOMAIN,${MARK}`, ...surgeRulesetToClashClassicalTextRuleset(content)];
break;
default:
throw new TypeError(`Unknown type: ${type as any}`);
throw new TypeError(`Unknown type: ${type}`);
}
return withBannerArray(title, description, date, _clashContent);
});

View File

@@ -426,15 +426,15 @@ class TimSort<T> {
this.tmp = new Array(this.tmpStorageLength);
this.stackLength = (
this.length < 120
? 5
: this.length < 1542
? 10
: this.length < 119151
? 19
: 40
);
if (this.length < 120) {
this.stackLength = 5;
} else if (this.length < 1542) {
this.stackLength = 10;
} else if (this.length < 119151) {
this.stackLength = 19;
} else {
this.stackLength = 40;
}
this.runStart = new Array(this.stackLength);
this.runLength = new Array(this.stackLength);