From 6ad839c0fe2f8de2bbaafb24f778b265e33df35b Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 23 Dec 2010 09:25:03 +0100 Subject: [PATCH] optimize DocumentSequence.Equals using hash codes of lines --- .../AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs index dbc183d4d7..91b0009070 100644 --- a/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs +++ b/src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/MyersDiff/DocumentSequence.cs @@ -16,6 +16,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.MyersDiff { this.document = document; this.hashCodes = new List(); + + for (int i = 1; i <= document.TotalNumberOfLines; i++) { + hashCodes.Add(document.GetLine(i).Text.GetHashCode()); + } } public int Size() @@ -30,10 +34,10 @@ namespace ICSharpCode.AvalonEdit.AddIn.MyersDiff if (seq == null) return false; - IDocumentLine thisLine = document.GetLine(i + 1); - IDocumentLine otherLine = seq.document.GetLine(j + 1); + int thisLineHash = hashCodes[i]; + int otherLineHash = seq.hashCodes[j]; - return thisLine.Text == otherLine.Text; + return thisLineHash == otherLineHash; } } }