Skip to content

Refactor CompileOperator: replace if-elseif chain with switch statement#280

Merged
fglock merged 3 commits intomasterfrom
fix-pat-t-tests
Mar 6, 2026
Merged

Refactor CompileOperator: replace if-elseif chain with switch statement#280
fglock merged 3 commits intomasterfrom
fix-pat-t-tests

Conversation

@fglock
Copy link
Owner

@fglock fglock commented Mar 6, 2026

Summary

  • Convert the large if-elseif chain in visitOperator to a switch statement
  • Extract 17+ helper methods for complex operators
  • Move exists/delete handling to CompileExistsDelete helper class
  • Remove "each" from getGenericOpcode to use dedicated handler
  • Consolidate dispatchOperator for common simple operators

Result

CompileOperator.visitOperator: 6,854 → 4,562 bytes (-33.5%)

All critical production methods now well under the 8,000 byte JIT compilation limit.

Test plan

  • ./gradlew classes testUnitParallel --parallel passes
  • Method size scan shows visitOperator at 4,562 bytes (safe zone)

Generated with Devin

fglock and others added 3 commits March 6, 2026 20:30
Convert the large if-elseif chain in visitOperator to a switch statement,
extracting operator handlers into dedicated helper methods. This improves
code readability and reduces method bytecode size.

Changes:
- Replace ~45 if-elseif branches with switch expression
- Extract 17+ helper methods for complex operators (visitSplice, visitReverse,
  visitKeys, visitChop, visitValues, visitArrayLastIndex, visitLength,
  visitDiamond, visitTransliterate, visitTie, visitAtan2, visitEach,
  visitGlob, visitDoFile, visitGoto, visitFileTestOp, visitIncrDecr)
- Move exists/delete handling to CompileExistsDelete helper class
- Remove "each" from getGenericOpcode to use dedicated handler
- Consolidate dispatchOperator for common simple operators

Result: visitOperator reduced from 6,854 to 4,562 bytes (-33.5%)

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
The file test operator check (op.startsWith("-") && op.length() == 2)
was catching the decrement operator -- before the main switch could
handle it. Added explicit exclusion for --.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
Consolidate multiple dispatch mechanisms (dispatchOperator, visitPopShift,
visitSimpleUnaryOp, visitGenericListOp, file test check) into one switch
for better readability and performance.

Generated with [Devin](https://cli.devin.ai/docs)

Co-Authored-By: Devin <noreply@cognition.ai>
@fglock fglock merged commit 1333757 into master Mar 6, 2026
2 checks passed
@fglock fglock deleted the fix-pat-t-tests branch March 6, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant