From 5e8f1116d9f2af82aa7ef36d4c84426bc835cf29 Mon Sep 17 00:00:00 2001 From: Jb Evain Date: Thu, 7 Nov 2019 08:58:50 -0800 Subject: [PATCH] Remove name cache that is not invalidated when renaming types --- Mono.Cecil/ModuleDefinition.cs | 16 ++++++++++++++-- Mono.Cecil/TypeDefinitionCollection.cs | 22 ---------------------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs index 707a1358f..b0cb2dd95 100644 --- a/Mono.Cecil/ModuleDefinition.cs +++ b/Mono.Cecil/ModuleDefinition.cs @@ -669,14 +669,26 @@ public TypeDefinition GetType (string fullName) if (position > 0) return GetNestedType (fullName); - return ((TypeDefinitionCollection) this.Types).GetType (fullName); + string @namespace, name; + TypeParser.SplitFullName (fullName, out @namespace, out name); + + return GetType (@namespace, name); } public TypeDefinition GetType (string @namespace, string name) { Mixin.CheckName (name); + if (@namespace == null) + @namespace = string.Empty; + + var types = this.Types; + for (int i = 0; i < types.Count; i++) { + var type = types [i]; + if (type.Namespace == @namespace && type.Name == name) + return type; + } - return ((TypeDefinitionCollection) this.Types).GetType (@namespace ?? string.Empty, name); + return null; } public IEnumerable GetTypes () diff --git a/Mono.Cecil/TypeDefinitionCollection.cs b/Mono.Cecil/TypeDefinitionCollection.cs index 95e39b9a6..6b4951e4f 100644 --- a/Mono.Cecil/TypeDefinitionCollection.cs +++ b/Mono.Cecil/TypeDefinitionCollection.cs @@ -22,19 +22,16 @@ namespace Mono.Cecil { sealed class TypeDefinitionCollection : Collection { readonly ModuleDefinition container; - readonly Dictionary name_cache; internal TypeDefinitionCollection (ModuleDefinition container) { this.container = container; - this.name_cache = new Dictionary (new RowEqualityComparer ()); } internal TypeDefinitionCollection (ModuleDefinition container, int capacity) : base (capacity) { this.container = container; - this.name_cache = new Dictionary (capacity, new RowEqualityComparer ()); } protected override void OnAdd (TypeDefinition item, int index) @@ -70,31 +67,12 @@ void Attach (TypeDefinition type) type.module = container; type.scope = container; - name_cache [new Slot (type.Namespace, type.Name)] = type; } void Detach (TypeDefinition type) { type.module = null; type.scope = null; - name_cache.Remove (new Slot (type.Namespace, type.Name)); - } - - public TypeDefinition GetType (string fullname) - { - string @namespace, name; - TypeParser.SplitFullName (fullname, out @namespace, out name); - - return GetType (@namespace, name); - } - - public TypeDefinition GetType (string @namespace, string name) - { - TypeDefinition type; - if (name_cache.TryGetValue (new Slot (@namespace, name), out type)) - return type; - - return null; } } }