@@ -460,6 +460,15 @@ private module ControlFlowGraphImpl {
460
460
)
461
461
}
462
462
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
+
463
472
/**
464
473
* Gets a `SwitchCase` that may be `pred`'s direct successor.
465
474
*
@@ -469,14 +478,15 @@ private module ControlFlowGraphImpl {
469
478
* that any default case comes after the last pattern case.
470
479
*/
471
480
private SwitchCase getASuccessorSwitchCase ( PatternCase pred ) {
472
- result .getParent ( ) = pred .getParent ( ) and
473
- result .getIndex ( ) > pred .getIndex ( ) and
474
481
// Note we do include `case null, default` (as well as plain old `default`) here.
475
482
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 ] )
480
490
)
481
491
}
482
492
0 commit comments