Skip to content

Commit

Permalink
Merge pull request #1455 from Jacky720/switchcaseplumbing
Browse files Browse the repository at this point in the history
Prevent blocks from being requeued in switch decompilation
  • Loading branch information
colinator27 authored Nov 12, 2023
2 parents 99381fd + e78ca8b commit c99e556
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions UndertaleModLib/Decompiler/Decompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4077,8 +4077,13 @@ private static Block DetermineSwitchEnd(Block start, Block end, Block meetPoint)
return meetPoint;

Queue<Block> blocks = new Queue<Block>();
// Preventing the same block and its children from being queued repeatedly
// becomes increasingly important on large switches. The HashSet should give
// good performance while preventing this type of duplication.
HashSet<Block> usedBlocks = new HashSet<Block>();

blocks.Enqueue(start);
usedBlocks.Add(start);
while (blocks.Count > 0)
{
Block test = blocks.Dequeue();
Expand All @@ -4087,10 +4092,16 @@ private static Block DetermineSwitchEnd(Block start, Block end, Block meetPoint)
return end;
if (test == meetPoint)
return meetPoint;

blocks.Enqueue(test.nextBlockTrue);
if (test.nextBlockTrue != test.nextBlockFalse)
if (!usedBlocks.Contains(test.nextBlockTrue))
{
blocks.Enqueue(test.nextBlockTrue);
usedBlocks.Add(test.nextBlockTrue);
}
if (!usedBlocks.Contains(test.nextBlockFalse))
{
blocks.Enqueue(test.nextBlockFalse);
usedBlocks.Add(test.nextBlockFalse);
}

}

Expand Down

0 comments on commit c99e556

Please sign in to comment.