diff options
author | Vitek Karas <10670590+vitek-karas@users.noreply.github.com> | 2022-08-08 14:52:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-08 14:52:14 +0300 |
commit | 4d524405b20345fb269e46ef2078e27acf26a127 (patch) | |
tree | 82ccbee6241a76a8898b3a5ad6180a1c40821522 | |
parent | dede5f58dc9b7296de884ed62688b35d5b154b78 (diff) |
[analyzer tool] Avoid exceptions when loading dependencies (#2949)
The existing code used exceptions as a way to determine if item is part of a dictionary. That is pretty expensive and slows down loading of the dependencies quite a bit (we do it A LOT).
Rewrite the code to avoid exceptions in this case.
-rw-r--r-- | src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs b/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs index 2507cae70..275756b01 100644 --- a/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs +++ b/src/analyzer/LinkerAnalyzerCore/DependencyGraph.cs @@ -89,27 +89,24 @@ namespace LinkerAnalyzer.Core public VertexData Vertex (string vertexName, bool create = false) { - VertexData vertex; - - try { - vertex = vertices[indexes[vertexName]]; - } catch (KeyNotFoundException) { - if (create) { - int index = vertices.Count; - vertex = new VertexData () { value = vertexName, index = index }; - vertices.Add (vertex); - indexes.Add (vertexName, index); - string prefix = vertexName.Substring (0, vertexName.IndexOf (':')); - if (counts.TryGetValue (prefix, out var count)) - counts[prefix] = count + 1; - else - counts[prefix] = 1; - //Console.WriteLine ("prefix " + prefix + " count " + counts[prefix]); - if (prefix == "TypeDef") { - Types.Add (vertex); - } - } else - return null; + if (indexes.TryGetValue (vertexName, out int index)) + return vertices[index]; + + if (!create) + return null; + + index = vertices.Count; + var vertex = new VertexData () { value = vertexName, index = index }; + vertices.Add (vertex); + indexes.Add (vertexName, index); + string prefix = vertexName.Substring (0, vertexName.IndexOf (':')); + if (counts.TryGetValue (prefix, out var count)) + counts[prefix] = count + 1; + else + counts[prefix] = 1; + //Console.WriteLine ("prefix " + prefix + " count " + counts[prefix]); + if (prefix == "TypeDef") { + Types.Add (vertex); } return vertex; |