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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target) Constructs a SWITCH with default maxGap of 1.SWITCH(int[] match, InstructionHandle[] targets, InstructionHandle target, int maxGap) Template for switch() constructs. -
Method Summary
Modifier and TypeMethodDescriptionGets the instruction.Gets the instruction list.private static booleanmatchIsOrdered(int[] match, int matchLength, int maxGap) private static voidsort(int l, int r, int[] match, InstructionHandle[] targets) Sorts match and targets array with QuickSort.
-
Field Details
-
instruction
-
-
Constructor Details
-
SWITCH
Constructs a SWITCH with default maxGap of 1.- Parameters:
match- array of match values.targets- The instructions to be branched to for each case.target- The default target.
-
SWITCH
Template for switch() constructs. If the match array can be sorted in ascending order with gaps no larger than maxGap 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 case.target- The default target.maxGap- maximum gap that may between case branches.
-
-
Method Details
-
matchIsOrdered
private static boolean matchIsOrdered(int[] match, int matchLength, int maxGap) - Returns:
- match is sorted in ascending order with no gap bigger than maxGap?
-
sort
Sorts match and targets array with QuickSort. -
getInstruction
Gets the instruction.- Returns:
- The instruction.
-
getInstructionList
Description copied from interface:CompoundInstructionGets the instruction list.- Specified by:
getInstructionListin interfaceCompoundInstruction- Returns:
- The instruction list.
-