Skip to content

Commit e702e36

Browse files
committed
perf(linter/plugins): optimize loops
1 parent 34fa651 commit e702e36

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

apps/oxlint/src-js/plugins/lint.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function lintFileImpl(
125125
// Get visitors for this file from all rules
126126
initCompiledVisitor();
127127

128-
for (let i = 0; i < ruleIds.length; i++) {
128+
for (let i = 0, len = ruleIds.length; i < len; i++) {
129129
const ruleId = ruleIds[i],
130130
ruleAndContext = registeredRules[ruleId];
131131

@@ -180,9 +180,11 @@ function lintFileImpl(
180180
}
181181

182182
// Run `after` hooks
183-
if (afterHooks.length !== 0) {
184-
for (const afterHook of afterHooks) {
185-
afterHook();
183+
const afterHooksLen = afterHooks.length;
184+
if (afterHooksLen !== 0) {
185+
for (let i = 0; i < afterHooksLen; i++) {
186+
// Don't call hook with `afterHooks` array as `this`, or user could mess with it
187+
(0, afterHooks[i])();
186188
}
187189
// Reset array, ready for next file
188190
afterHooks.length = 0;

0 commit comments

Comments
 (0)