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 @@ -41,6 +41,8 @@ namespace ICSharpCode.ILSpy
/// <summary>Dirty flag, used to mark modifications so that the list is saved later</summary>
bool dirty;
internal readonly ConcurrentDictionary<string, LoadedAssembly> assemblyLookupCache = new ConcurrentDictionary<string, LoadedAssembly>();
/// <summary>
/// The assemblies in this list.
/// Needs locking for multi-threaded access!
@ -101,6 +103,7 @@ namespace ICSharpCode.ILSpy @@ -101,6 +103,7 @@ namespace ICSharpCode.ILSpy
void Assemblies_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
assemblyLookupCache.Clear();
// 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.
if (!dirty) {
@ -111,6 +114,7 @@ namespace ICSharpCode.ILSpy @@ -111,6 +114,7 @@ namespace ICSharpCode.ILSpy
delegate {
dirty = false;
AssemblyListManager.SaveList(this);
assemblyLookupCache.Clear();
})
);
}

9
ILSpy/LoadedAssembly.cs

@ -17,11 +17,11 @@ @@ -17,11 +17,11 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Threading;
using Mono.Cecil;
namespace ICSharpCode.ILSpy
@ -133,6 +133,8 @@ namespace ICSharpCode.ILSpy @@ -133,6 +133,8 @@ namespace ICSharpCode.ILSpy
if (!disposed) {
disposed = true;
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 @@ -177,6 +179,11 @@ namespace ICSharpCode.ILSpy
}
public LoadedAssembly LookupReferencedAssembly(string fullName)
{
return assemblyList.assemblyLookupCache.GetOrAdd(fullName, LookupReferencedAssemblyInternal);
}
LoadedAssembly LookupReferencedAssemblyInternal(string fullName)
{
foreach (LoadedAssembly asm in assemblyList.GetAssemblies()) {
if (asm.AssemblyDefinition != null && fullName.Equals(asm.AssemblyDefinition.FullName, StringComparison.OrdinalIgnoreCase))

Loading…
Cancel
Save