@@ -92,21 +92,39 @@ static bool IsMethodSupported (MethodDefinition method)
92
92
return true ;
93
93
}
94
94
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 )
96
96
{
97
97
foreach ( var instr in instructions ) {
98
98
switch ( instr . OpCode . FlowControl ) {
99
99
case FlowControl . Branch :
100
100
case FlowControl . Cond_Branch :
101
101
if ( 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
+ }
105
114
} else {
106
115
foreach ( 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
+ }
110
128
}
111
129
}
112
130
@@ -1175,6 +1193,15 @@ int GetInstructionIndex (Instruction instruction)
1175
1193
return idx ;
1176
1194
}
1177
1195
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
+
1178
1205
bool GetOperandsConstantValues ( int index , out object ? left , out object ? right )
1179
1206
{
1180
1207
Debug . Assert ( FoldedInstructions != null ) ;
@@ -1213,7 +1240,7 @@ static bool IsPairedStlocLdloc (Instruction first, Instruction second)
1213
1240
bool IsJumpTargetRange ( int firstInstr , int lastInstr )
1214
1241
{
1215
1242
Debug . Assert ( FoldedInstructions != null ) ;
1216
- return HasJumpIntoTargetRange ( FoldedInstructions , firstInstr , lastInstr , GetInstructionIndex ) ;
1243
+ return HasJumpIntoTargetRange ( FoldedInstructions , firstInstr , lastInstr , TryGetInstructionIndex ) ;
1217
1244
}
1218
1245
}
1219
1246
0 commit comments