From 414dd7f00872de7badc43b71b57d2014db07326f Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Wed, 28 Feb 2024 13:37:10 +0800 Subject: [PATCH] TryGetValue for performance --- src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs b/src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs index 049a1444e..0d7a1578c 100644 --- a/src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs +++ b/src/Neo.Compiler.CSharp/Optimizer/Strategies/Reachability.cs @@ -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]); @@ -160,7 +159,7 @@ public static Dictionary { Script script = nef.Script; Dictionary coveredMap = new(); - foreach ((int addr, Instruction inst) in script.EnumerateInstructions()) + foreach ((int addr, Instruction _) in script.EnumerateInstructions()) coveredMap.Add(addr, false); Dictionary publicMethodStartingAddressToName = new();