Refactor CompileOperator: replace if-elseif chain with switch statement#280
Merged
Refactor CompileOperator: replace if-elseif chain with switch statement#280
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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 --parallelpassesGenerated with Devin