Skip to content

Commit f91e0dc

Browse files
committed
perf(linter/plugins): initialize lineStartOffsets as [0]
1 parent 57daa54 commit f91e0dc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ let sourceByteLen: number = 0;
3535
let ast: Program | null = null;
3636

3737
// Lazily populated when `SOURCE_CODE.lines` is accessed.
38+
// `lineStartOffsets` starts as `[0]`, and `resetSource` doesn't remove that initial element, so it's never empty.
3839
const lines: string[] = [],
39-
lineStartOffsets: number[] = [];
40+
lineStartOffsets: number[] = [0];
4041

4142
// Lazily populated when `SOURCE_CODE.visitorKeys` is accessed.
4243
let visitorKeys: { [key: string]: string[] } | null = null;
@@ -101,7 +102,7 @@ function initLines(): void {
101102
* and uses match.index to get the correct line start indices.
102103
*/
103104

104-
lineStartOffsets.push(0);
105+
// Note: `lineStartOffsets` starts as `[0]`
105106
let lastOffset = 0, offset, match;
106107
while ((match = LINE_BREAK_PATTERN.exec(sourceText))) {
107108
offset = match.index;
@@ -126,7 +127,7 @@ export function resetSource(): void {
126127
sourceText = null;
127128
ast = null;
128129
lines.length = 0;
129-
lineStartOffsets.length = 0;
130+
lineStartOffsets.length = 1;
130131
}
131132

132133
// `SourceCode` object.

0 commit comments

Comments
 (0)