|
1 |
| -// Copyright (c) 2018 Siegfried Pammer |
| 1 | +// Copyright (c) 2018 Siegfried Pammer |
2 | 2 | //
|
3 | 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
4 | 4 | // software and associated documentation files (the "Software"), to deal in the Software
|
@@ -637,10 +637,25 @@ leave IL_003e (nop)
|
637 | 637 | // Finally is empty and redundant. But we'll delete the block only if there's a PinnedRegion.
|
638 | 638 | if (!(tryFinally.TryBlock is BlockContainer tryContainer))
|
639 | 639 | return;
|
640 |
| - if (tryContainer.SingleInstruction() is PinnedRegion pinnedRegion) |
| 640 | + if (tryContainer.Blocks.Count != 1) |
| 641 | + return; |
| 642 | + var tryBlock = tryContainer.Blocks[0]; |
| 643 | + if (tryBlock.Instructions.Count == 1) |
641 | 644 | {
|
642 |
| - context.Step("Removing try-finally around PinnedRegion", pinnedRegion); |
643 |
| - tryFinally.ReplaceWith(pinnedRegion); |
| 645 | + if (tryBlock.Instructions[0] is PinnedRegion pinnedRegion) |
| 646 | + { |
| 647 | + context.Step("Removing try-finally around PinnedRegion", pinnedRegion); |
| 648 | + tryFinally.ReplaceWith(pinnedRegion); |
| 649 | + } |
| 650 | + } |
| 651 | + else if (tryBlock.Instructions.Count == 2) |
| 652 | + { |
| 653 | + if (tryBlock.Instructions[0] is PinnedRegion pinnedRegion && |
| 654 | + tryBlock.Instructions[1].MatchLeave(tryContainer)) |
| 655 | + { |
| 656 | + context.Step("Removing try-finally around PinnedRegion", pinnedRegion); |
| 657 | + tryFinally.ReplaceWith(pinnedRegion); |
| 658 | + } |
644 | 659 | }
|
645 | 660 | }
|
646 | 661 | }
|
|
0 commit comments