Browse Source

Cache assembly lookup results - improves performance (especially for failed lookups)

pull/252/head
Daniel Grunwald 14 years ago
parent
commit
a318ce67be
  1. 4
      ILSpy/AssemblyList.cs
  2. 9
      ILSpy/LoadedAssembly.cs

4
ILSpy/AssemblyList.cs

@ -41,6 +41,8 @@ namespace ICSharpCode.ILSpy
/// <summary>Dirty flag, used to mark modifications so that the list is saved later</summary> /// <summary>Dirty flag, used to mark modifications so that the list is saved later</summary>
bool dirty; bool dirty;
internal readonly ConcurrentDictionary<string, LoadedAssembly> assemblyLookupCache = new ConcurrentDictionary<string, LoadedAssembly>();
/// <summary> /// <summary>
/// The assemblies in this list. /// The assemblies in this list.
/// Needs locking for multi-threaded access! /// Needs locking for multi-threaded access!
@ -101,6 +103,7 @@ namespace ICSharpCode.ILSpy
void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{ {
assemblyLookupCache.Clear();
// Whenever the assembly list is modified, mark it as dirty // Whenever the assembly list is modified, mark it as dirty
// and enqueue a task that saves it once the UI has finished modifying the assembly list. // and enqueue a task that saves it once the UI has finished modifying the assembly list.
if (!dirty) { if (!dirty) {
@ -111,6 +114,7 @@ namespace ICSharpCode.ILSpy
delegate { delegate {
dirty = false; dirty = false;
AssemblyListManager.SaveList(this); AssemblyListManager.SaveList(this);
assemblyLookupCache.Clear();
}) })
); );
} }

9
ILSpy/LoadedAssembly.cs

@ -17,11 +17,11 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Concurrent;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading; using System.Windows.Threading;
using Mono.Cecil; using Mono.Cecil;
namespace ICSharpCode.ILSpy namespace ICSharpCode.ILSpy
@ -133,6 +133,8 @@ namespace ICSharpCode.ILSpy
if (!disposed) { if (!disposed) {
disposed = true; disposed = true;
assemblyLoadDisableCount--; assemblyLoadDisableCount--;
// clear the lookup cache since we might have stored the lookups failed due to DisableAssemblyLoad()
MainWindow.Instance.CurrentAssemblyList.assemblyLookupCache.Clear();
} }
} }
} }
@ -177,6 +179,11 @@ namespace ICSharpCode.ILSpy
} }
public LoadedAssembly LookupReferencedAssembly(string fullName) public LoadedAssembly LookupReferencedAssembly(string fullName)
{
return assemblyList.assemblyLookupCache.GetOrAdd(fullName, LookupReferencedAssemblyInternal);
}
LoadedAssembly LookupReferencedAssemblyInternal(string fullName)
{ {
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) { foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {
if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase)) if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase))

Loading…
Cancel
Save