Skip to content

Commit d9a1b32

Browse files
committed
perf(linter/plugins): avoid array lookups where possible in CFG visitor (#21940)
Small optimization to CFG visitor. Skip array lookups unless the result is actually used.
1 parent fefefd8 commit d9a1b32

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

  • apps/oxlint/src-js/plugins

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ export function walkProgramWithCfg(
105105

106106
if (typeId < NODE_TYPES_COUNT) {
107107
// Enter node. `typeId` is node type ID.
108-
const node = stepData[i] as Node;
109108
const visit = visitors[typeId];
110109

111110
if (typeId < LEAF_NODE_TYPES_COUNT) {
112111
// Leaf node
113112
if (visit !== null) {
114113
debugAssertIsFunction(visit);
115-
visit(node);
114+
visit(stepData[i] as Node);
116115
}
117116
// Don't add node to `ancestors`, because we don't visit leaf nodes on exit
118117
} else {
119118
// Non-leaf node
119+
const node = stepData[i] as Node;
120120
if (visit !== null) {
121121
debugAssertIsEnterExitObject(visit);
122122
const { enter } = visit;
@@ -133,15 +133,14 @@ export function walkProgramWithCfg(
133133
// (`cmp` is essentially subtraction), in which case `- EXIT_TYPE_ID_OFFSET` would be cheaper than
134134
// `& EXIT_TYPE_ID_OFFSET - 1`. That's just speculation though! Have not checked what ASM TurboFan generates.
135135
typeId -= EXIT_TYPE_ID_OFFSET;
136-
const node = stepData[i] as Node;
137136

138137
ancestors.shift();
139138

140139
const enterExit = visitors[typeId];
141140
if (enterExit !== null) {
142141
debugAssertIsEnterExitObject(enterExit);
143142
const { exit } = enterExit;
144-
if (exit !== null) exit(node);
143+
if (exit !== null) exit(stepData[i] as Node);
145144
}
146145
} else {
147146
// Call method (CFG event). `typeId` is event type ID.

0 commit comments

Comments
 (0)