@@ -92,21 +92,39 @@ static bool IsMethodSupported (MethodDefinition method)
9292return true ;
9393}
9494
95- static bool HasJumpIntoTargetRange ( Collection < Instruction > instructions , int firstInstr , int lastInstr , Func < Instruction , int > ? mapping = null )
95+ static bool HasJumpIntoTargetRange ( Collection < Instruction > instructions , int firstInstr , int lastInstr , Func < Instruction , int ? > ? mapping = null )
9696{
9797foreach ( var instr in instructions ) {
9898switch ( instr . OpCode . FlowControl ) {
9999case FlowControl . Branch :
100100case FlowControl . Cond_Branch :
101101if ( instr . Operand is Instruction target ) {
102- int index = mapping == null ? instructions . IndexOf ( target ) : mapping ( target ) ;
103- if ( index >= firstInstr && index <= lastInstr )
104- return true ;
102+ if ( mapping != null && mapping ( target ) is int index ) {
103+ if ( index >= firstInstr && index <= lastInstr ) {
104+ return true ;
105+ }
106+ }
107+ else {
108+ for ( int i = firstInstr ; i <= lastInstr ; i ++ ) {
109+ if ( instructions [ i ] == target ) {
110+ return true ;
111+ }
112+ }
113+ }
105114} else {
106115foreach ( var rtarget in ( Instruction [ ] ) instr . Operand ) {
107- int index = mapping == null ? instructions . IndexOf ( rtarget ) : mapping ( rtarget ) ;
108- if ( index >= firstInstr && index <= lastInstr )
109- return true ;
116+ if ( mapping != null && mapping ( rtarget ) is int index ) {
117+ if ( index >= firstInstr && index <= lastInstr ) {
118+ return true ;
119+ }
120+ }
121+ else {
122+ for ( int i = firstInstr ; i <= lastInstr ; i ++ ) {
123+ if ( instructions [ i ] == rtarget ) {
124+ return true ;
125+ }
126+ }
127+ }
110128}
111129}
112130
@@ -1175,6 +1193,15 @@ int GetInstructionIndex (Instruction instruction)
11751193return idx ;
11761194}
11771195
1196+ int ? TryGetInstructionIndex ( Instruction instruction )
1197+ {
1198+ Debug . Assert ( mapping != null ) ;
1199+ if ( mapping . TryGetValue ( instruction , out int idx ) )
1200+ return idx ;
1201+
1202+ return null ;
1203+ }
1204+
11781205bool GetOperandsConstantValues ( int index , out object ? left , out object ? right )
11791206{
11801207Debug . Assert ( FoldedInstructions != null ) ;
@@ -1213,7 +1240,7 @@ static bool IsPairedStlocLdloc (Instruction first, Instruction second)
12131240bool IsJumpTargetRange ( int firstInstr , int lastInstr )
12141241{
12151242Debug . Assert ( FoldedInstructions != null ) ;
1216- return HasJumpIntoTargetRange ( FoldedInstructions , firstInstr , lastInstr , GetInstructionIndex ) ;
1243+ return HasJumpIntoTargetRange ( FoldedInstructions , firstInstr , lastInstr , TryGetInstructionIndex ) ;
12171244}
12181245}
12191246