Skip to content

Commit

Permalink
TryGetValue for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecate2 committed Feb 28, 2024
1 parent 61b9837 commit 414dd7f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public static (NefFile, ContractManifest, JObject) RemoveUncoveredInstructions(N
simplifiedScript.Add((byte)i.OpCode);
int operandSizeLength = OperandSizePrefixTable[(int)i.OpCode];
simplifiedScript = simplifiedScript.Concat(BitConverter.GetBytes(i.Operand.Length)[0..operandSizeLength]).ToList();
if (jumpInstructionSourceToTargets.ContainsKey(i))
if (jumpInstructionSourceToTargets.TryGetValue(i, out Instruction? dst))
{
Instruction dst = jumpInstructionSourceToTargets[i];
int delta = (int)simplifiedInstructionsToAddress[dst]! - a;
if (i.OpCode == OpCode.JMP || conditionalJump.Contains(i.OpCode) || i.OpCode == OpCode.CALL || i.OpCode == OpCode.ENDTRY)
simplifiedScript.Add(BitConverter.GetBytes(delta)[0]);
Expand Down Expand Up @@ -160,7 +159,7 @@ public static Dictionary<int, bool>
{
Script script = nef.Script;
Dictionary<int, bool> coveredMap = new();
foreach ((int addr, Instruction inst) in script.EnumerateInstructions())
foreach ((int addr, Instruction _) in script.EnumerateInstructions())
coveredMap.Add(addr, false);

Dictionary<int, string> publicMethodStartingAddressToName = new();
Expand Down

0 comments on commit 414dd7f

Please sign in to comment.