Browse Source

Minor performance improvement for AvalonEdit (e.g. when indenting all lines in the file).

pull/14/head
Daniel Grunwald 15 years ago
parent
commit
f4b0c54f2d
  1. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs
  2. 9
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs
  3. 6
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/OffsetChangeMap.cs

@ -110,8 +110,10 @@ namespace ICSharpCode.AvalonEdit.Document
/// </summary> /// </summary>
public int GetNewOffset(int offset, AnchorMovementType movementType) public int GetNewOffset(int offset, AnchorMovementType movementType)
{ {
foreach (OffsetChangeMapEntry entry in this) { IList<OffsetChangeMapEntry> items = this.Items;
offset = entry.GetNewOffset(offset, movementType); int count = items.Count;
for (int i = 0; i < count; i++) {
offset = items[i].GetNewOffset(offset, movementType);
} }
return offset; return offset;
} }

9
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/Caret.cs

@ -86,6 +86,15 @@ namespace ICSharpCode.AvalonEdit.Editing
} }
} }
/// <summary>
/// Gets the caret position without validating it.
/// </summary>
internal TextViewPosition NonValidatedPosition {
get {
return position;
}
}
/// <summary> /// <summary>
/// Gets/Sets the location of the caret. /// Gets/Sets the location of the caret.
/// The getter of this property is faster than <see cref="Position"/> because it doesn't have /// The getter of this property is faster than <see cref="Position"/> because it doesn't have

6
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -320,7 +320,9 @@ namespace ICSharpCode.AvalonEdit.Editing
public RestoreCaretAndSelectionUndoAction(TextArea textArea) public RestoreCaretAndSelectionUndoAction(TextArea textArea)
{ {
this.textAreaReference = new WeakReference(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; this.selection = textArea.Selection;
} }
@ -379,7 +381,7 @@ namespace ICSharpCode.AvalonEdit.Editing
if (value == null) if (value == null)
throw new ArgumentNullException("value"); throw new ArgumentNullException("value");
if (!object.Equals(selection, 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) { if (textView != null) {
ISegment oldSegment = selection.SurroundingSegment; ISegment oldSegment = selection.SurroundingSegment;
ISegment newSegment = value.SurroundingSegment; ISegment newSegment = value.SurroundingSegment;

Loading…
Cancel
Save