Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove name cache that is not invalidated when renaming types #629

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Mono.Cecil/ModuleDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeDefinition> GetTypes ()
Expand Down
22 changes: 0 additions & 22 deletions Mono.Cecil/TypeDefinitionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ namespace Mono.Cecil {
sealed class TypeDefinitionCollection : Collection<TypeDefinition> {

readonly ModuleDefinition container;
readonly Dictionary<Slot, TypeDefinition> name_cache;

internal TypeDefinitionCollection (ModuleDefinition container)
{
this.container = container;
this.name_cache = new Dictionary<Slot, TypeDefinition> (new RowEqualityComparer ());
}

internal TypeDefinitionCollection (ModuleDefinition container, int capacity)
: base (capacity)
{
this.container = container;
this.name_cache = new Dictionary<Slot, TypeDefinition> (capacity, new RowEqualityComparer ());
}

protected override void OnAdd (TypeDefinition item, int index)
Expand Down Expand Up @@ -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;
}
}
}