diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs index ec19b0b363..2916ed7cb8 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/DefaultChangeWatcher.cs @@ -83,9 +83,11 @@ namespace ICSharpCode.AvalonEdit.AddIn } else { changeList.Clear(); + Dictionary hashes = new Dictionary(); + MyersDiff.MyersDiff diff = new MyersDiff.MyersDiff( - new DocumentSequence(baseDocument), - new DocumentSequence(document) + new DocumentSequence(baseDocument, hashes), + new DocumentSequence(document, hashes) ); changeList.Add(new LineChangeInfo(ChangeType.None, "")); diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs index 91b0009070..3c768d404a 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs @@ -9,35 +9,36 @@ namespace ICSharpCode.AvalonEdit.AddIn.MyersDiff { public class DocumentSequence : ISequence { - IDocument document; - List hashCodes; + int[] hashes; - public DocumentSequence(IDocument document) + public DocumentSequence(IDocument document, Dictionary hashDict) { - this.document = document; - this.hashCodes = new List(); + this.hashes = new int[document.TotalNumberOfLines]; for (int i = 1; i <= document.TotalNumberOfLines; i++) { - hashCodes.Add(document.GetLine(i).Text.GetHashCode()); + string text = document.GetLine(i).Text; + int hash; + if (!hashDict.TryGetValue(text, out hash)) { + hash = hashDict.Count; + hashDict.Add(text, hash); + } + hashes[i - 1] = hash; } } public int Size() { - return document.TotalNumberOfLines; + return hashes.Length; } - public bool Equals(int i, ISequence other, int j) + public bool Equals(int thisIdx, ISequence other, int otherIdx) { DocumentSequence seq = other as DocumentSequence; if (seq == null) return false; - int thisLineHash = hashCodes[i]; - int otherLineHash = seq.hashCodes[j]; - - return thisLineHash == otherLineHash; + return hashes[thisIdx] == seq.hashes[otherIdx]; } } }