Skip to content

Commit 8d166dc

Browse files
committed
perf(MiddleWare): 优化 MiddleWare 类中的钩子调用方式
- 将 hooks[0].callback(...inputs) 修改为 hooks[0].callback.apply(null, inputs) - 这种改动可以提高函数调用的性能,特别是在输入参数较多的情况下
1 parent ed44d9b commit 8d166dc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/MiddleWare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class MiddleWare<I extends unknown[], O> {
2626
const hooks = this.#hooks.filter((hook) => hook.patterns.find((pattern) => minimatch(pth, pattern)));
2727

2828
if (hooks.length === 0) return undefined;
29-
if (hooks.length === 1) return hooks[0].callback(...inputs);
29+
if (hooks.length === 1) return hooks[0].callback.apply(null, inputs);
3030

3131
throw new Error(`Multiple hooks found for file ${pth}`);
3232
}

0 commit comments

Comments
 (0)