From f4b0c54f2da143fa4072e948acb2babd561ea063 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sat, 18 Dec 2010 17:01:14 +0100 Subject: [PATCH] Minor performance improvement for AvalonEdit (e.g. when indenting all lines in the file). --- .../ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs | 6 ++++-- .../AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs | 9 +++++++++ .../ICSharpCode.AvalonEdit/Editing/TextArea.cs | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs index c18221c3e3..9ce98fc719 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs @@ -110,8 +110,10 @@ namespace ICSharpCode.AvalonEdit.Document /// public int GetNewOffset(int offset, AnchorMovementType movementType) { - foreach (OffsetChangeMapEntry entry in this) { - offset = entry.GetNewOffset(offset, movementType); + IList items = this.Items; + int count = items.Count; + for (int i = 0; i < count; i++) { + offset = items[i].GetNewOffset(offset, movementType); } return offset; } diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs index db09ab5d32..98a2e67e6e 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs @@ -86,6 +86,15 @@ namespace ICSharpCode.AvalonEdit.Editing } } + /// + /// Gets the caret position without validating it. + /// + internal TextViewPosition NonValidatedPosition { + get { + return position; + } + } + /// /// Gets/Sets the location of the caret. /// The getter of this property is faster than because it doesn't have diff --git a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs index f74705f0c6..a38fe7bfb9 100644 --- a/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs +++ b/src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs @@ -320,7 +320,9 @@ namespace ICSharpCode.AvalonEdit.Editing public RestoreCaretAndSelectionUndoAction(TextArea textArea) { this.textAreaReference = new WeakReference(textArea); - this.caretPosition = textArea.Caret.Position; + // Just save the old caret position, no need to validate here. + // If we restore it, we'll validate it anyways. + this.caretPosition = textArea.Caret.NonValidatedPosition; this.selection = textArea.Selection; } @@ -379,7 +381,7 @@ namespace ICSharpCode.AvalonEdit.Editing if (value == null) throw new ArgumentNullException("value"); if (!object.Equals(selection, value)) { - Debug.WriteLine("Selection change from " + selection + " to " + value); + //Debug.WriteLine("Selection change from " + selection + " to " + value); if (textView != null) { ISegment oldSegment = selection.SurroundingSegment; ISegment newSegment = value.SurroundingSegment;