From f00cbc8f50a651342bf53fbb7c1d79d9cd1c311d Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 20 Aug 2013 20:30:58 +0200 Subject: [PATCH] add global cache for Cecil's AssemblyDefinition in ILSpyDecompilerService --- .../ILSpyAddIn/ILSpyDecompilerService.cs | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs index a7a7d7dae9..8384341830 100644 --- a/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs +++ b/src/AddIns/DisplayBindings/ILSpyAddIn/ILSpyDecompilerService.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; +using System.Collections.Generic; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; @@ -20,6 +21,8 @@ namespace ICSharpCode.ILSpyAddIn /// public static class ILSpyDecompilerService { + static readonly Dictionary assemblyCache = new Dictionary(); + class ILSpyAssemblyResolver : DefaultAssemblySearcher, IAssemblyResolver { public ILSpyAssemblyResolver(FileName fileName) @@ -27,6 +30,20 @@ namespace ICSharpCode.ILSpyAddIn { } + AssemblyDefinition Resolve(DomAssemblyName name, ReaderParameters parameters) + { + var file = FindAssembly(name); + if (file == null) return null; + AssemblyDefinition asm; + lock (assemblyCache) { + if (!assemblyCache.TryGetValue(file, out asm)) { + asm = AssemblyDefinition.ReadAssembly(file, parameters); + assemblyCache.Add(file, asm); + } + } + return asm; + } + public AssemblyDefinition Resolve(AssemblyNameReference name) { return Resolve(name, new ReaderParameters()); @@ -34,9 +51,7 @@ namespace ICSharpCode.ILSpyAddIn public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters) { - var file = FindAssembly(new DomAssemblyName(name.FullName)); - if (file == null) return null; - return AssemblyDefinition.ReadAssembly(file, parameters); + return Resolve(new DomAssemblyName(name.FullName), parameters); } public AssemblyDefinition Resolve(string fullName) @@ -46,9 +61,7 @@ namespace ICSharpCode.ILSpyAddIn public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters) { - var file = FindAssembly(new DomAssemblyName(fullName)); - if (file == null) return null; - return AssemblyDefinition.ReadAssembly(file, parameters); + return Resolve(new DomAssemblyName(fullName), parameters); } }