Skip to content

Commit 86f7d5f

Browse files
committed
Avoid property lookups on each turn of loop
1 parent 7744774 commit 86f7d5f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ export const SOURCE_CODE = Object.freeze({
226226

227227
const commentsAfter: Comment[] = [];
228228

229-
for (let i = 0; i < comments.length; i++) {
229+
const commentsLength = comments.length;
230+
for (let i = 0; i < commentsLength; i++) {
230231
const comment = comments[i];
231232
const commentStart = comment.start;
232233

@@ -294,9 +295,10 @@ export const SOURCE_CODE = Object.freeze({
294295
commentsExistBetween(nodeOrToken1: NodeOrToken, nodeOrToken2: NodeOrToken): boolean {
295296
// Find the first comment after `nodeOrToken1` ends.
296297
// Check if it ends before `nodeOrToken2` starts.
297-
const { comments } = ast;
298+
const { comments } = ast,
299+
commentsLength = comments.length;
298300
const betweenRangeStart = nodeOrToken1.range[1]; // end
299-
for (let i = 0; i < comments.length; i++) {
301+
for (let i = 0; i < commentsLength; i++) {
300302
const comment = comments[i];
301303
if (comment.start >= betweenRangeStart) {
302304
return comment.end <= nodeOrToken2.range[0]; // start

0 commit comments

Comments
 (0)