@@ -460,6 +460,15 @@ private module ControlFlowGraphImpl {
460460 )
461461 }
462462
463+ private int lastCaseIndex ( StmtParent switch ) {
464+ result = max ( int i | any ( SwitchCase c ) .isNthCaseOf ( switch , i ) )
465+ }
466+
467+ // Join order engineering -- first determine the switch block and the case indices required, then retrieve them.
468+ bindingset [ switch, i]
469+ pragma [ inline_late]
470+ private predicate isNthCaseOf ( StmtParent switch , SwitchCase c , int i ) { c .isNthCaseOf ( switch , i ) }
471+
463472 /**
464473 * Gets a `SwitchCase` that may be `pred`'s direct successor.
465474 *
@@ -469,14 +478,15 @@ private module ControlFlowGraphImpl {
469478 * that any default case comes after the last pattern case.
470479 */
471480 private SwitchCase getASuccessorSwitchCase ( PatternCase pred ) {
472- result .getParent ( ) = pred .getParent ( ) and
473- result .getIndex ( ) > pred .getIndex ( ) and
474481 // Note we do include `case null, default` (as well as plain old `default`) here.
475482 not result .( ConstCase ) .getValue ( _) instanceof NullLiteral and
476- (
477- result .getIndex ( ) <= getNextPatternCase ( pred ) .getIndex ( )
478- or
479- not exists ( getNextPatternCase ( pred ) )
483+ exists ( int maxCaseIndex , StmtParent switch |
484+ switch = pred .getParent ( ) and
485+ if exists ( getNextPatternCase ( pred ) )
486+ then maxCaseIndex = getNextPatternCase ( pred ) .getCaseIndex ( )
487+ else maxCaseIndex = lastCaseIndex ( switch )
488+ |
489+ isNthCaseOf ( switch , result , [ pred .getCaseIndex ( ) + 1 .. maxCaseIndex ] )
480490 )
481491 }
482492
0 commit comments