Package org.apache.bcel.generic
Class SWITCH
java.lang.Object
org.apache.bcel.generic.SWITCH
- All Implemented Interfaces:
CompoundInstruction
SWITCH - Branch depending on int value, generates either LOOKUPSWITCH or
TABLESWITCH instruction, depending on whether the match values (int[]) can be
sorted with no gaps between the numbers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Select
private int[]
private int
private InstructionHandle[]
-
Constructor Summary
ConstructorsConstructorDescriptionSWITCH
(int[] match, InstructionHandle[] targets, InstructionHandle target) SWITCH
(int[] match, InstructionHandle[] targets, InstructionHandle target, int max_gap) Template for switch() constructs. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
fillup
(int max_gap, InstructionHandle target) private boolean
matchIsOrdered
(int max_gap) private void
sort
(int l, int r) Sort match and targets array with QuickSort.
-
Field Details
-
match
private int[] match -
targets
-
instruction
-
matchLength
private int matchLength
-
-
Constructor Details
-
SWITCH
Template for switch() constructs. If the match array can be sorted in ascending order with gaps no larger than max_gap between the numbers, a TABLESWITCH instruction is generated, and a LOOKUPSWITCH otherwise. The former may be more efficient, but needs more space. Note, that the key array always will be sorted, though we leave the original arrays unaltered.- Parameters:
match
- array of match values (case 2: ... case 7: ..., etc.)targets
- the instructions to be branched to for each casetarget
- the default targetmax_gap
- maximum gap that may between case branches
-
SWITCH
-
-
Method Details
-
fillup
-
sort
private void sort(int l, int r) Sort match and targets array with QuickSort. -
matchIsOrdered
private boolean matchIsOrdered(int max_gap) - Returns:
- match is sorted in ascending order with no gap bigger than max_gap?
-
getInstructionList
- Specified by:
getInstructionList
in interfaceCompoundInstruction
-
getInstruction
-