From 18a2366f6c587f1691ac89e7ee998b12e3f04ebd Mon Sep 17 00:00:00 2001 From: Eusebiu Marcu Date: Mon, 14 Mar 2011 21:12:23 +0200 Subject: [PATCH] cache the Inverted list --- ICSharpCode.Decompiler/CodeMappings.cs | 50 +++++++------------------- 1 file changed, 12 insertions(+), 38 deletions(-) diff --git a/ICSharpCode.Decompiler/CodeMappings.cs b/ICSharpCode.Decompiler/CodeMappings.cs index b5843df9a..f2c961489 100644 --- a/ICSharpCode.Decompiler/CodeMappings.cs +++ b/ICSharpCode.Decompiler/CodeMappings.cs @@ -50,9 +50,8 @@ namespace ICSharpCode.Decompiler .FindAll(m => m.SourceCodeLine == this.SourceCodeLine) .ConvertAll(m => m.ILInstructionOffset); - // add inverted - currentList.AddRange(MemberMapping.GetInvertedList()); + currentList.AddRange(MemberMapping.InvertedList); var resultList = new List(); foreach (var element in ILRange.OrderAndJoint(currentList)) { @@ -62,38 +61,6 @@ namespace ICSharpCode.Decompiler return resultList.ToArray(); } - - sealed class SourceCodeMappingComparer : IEqualityComparer - { - public bool Equals(SourceCodeMapping x, SourceCodeMapping y) - { - //Check whether the compared objects reference the same data. - if (Object.ReferenceEquals(x, y)) return true; - - //Check whether any of the compared objects is null. - if (Object.ReferenceEquals(x, null) || Object.ReferenceEquals(y, null)) - return false; - - return x.ILInstructionOffset.From == y.ILInstructionOffset.From && - x.ILInstructionOffset.To == y.ILInstructionOffset.To && - x.SourceCodeLine == y.SourceCodeLine; - } - - public int GetHashCode(SourceCodeMapping map) - { - //Check whether the object is null - if (Object.ReferenceEquals(map, null)) return 0; - - //Get hash code for the ILInstructionOffset field if it is not null. - int hashRange = map.ILInstructionOffset == null ? 0 : map.ILInstructionOffset.GetHashCode(); - - //Get hash code for the SourceCodeLine field. - int hashLine = map.SourceCodeLine.GetHashCode(); - - //Calculate the hash code. - return hashRange ^ hashLine; - } - } } /// @@ -101,6 +68,8 @@ namespace ICSharpCode.Decompiler /// public sealed class MemberMapping { + IEnumerable invertedList; + /// /// Gets or sets the type of the mapping. /// @@ -126,11 +95,16 @@ namespace ICSharpCode.Decompiler /// E.g.: for (0-9, 11-14, 14-18, 21-25) => (9-11,18-21). /// /// IL Range inverted list. - public IEnumerable GetInvertedList() + public IEnumerable InvertedList { - var list = MemberCodeMappings.ConvertAll( - s => new ILRange { From = s.ILInstructionOffset.From, To = s.ILInstructionOffset.To }); - return ILRange.Invert(list, CodeSize); + get { + if (invertedList == null) { + var list = MemberCodeMappings.ConvertAll( + s => new ILRange { From = s.ILInstructionOffset.From, To = s.ILInstructionOffset.To }); + invertedList = ILRange.Invert(list, CodeSize); + } + return invertedList; + } } }