Permalink
Browse files

Minor optimization for ReadOnlyDocument.

  • Loading branch information...
1 parent d54a6f0 commit 6a8c1130b558c4d44f0d7df2eca124e4a4e4bb1f @dgrunwald dgrunwald committed Dec 22, 2010
Showing with 9 additions and 12 deletions.
  1. +9 −12 src/Main/Base/Project/Src/Editor/ReadOnlyDocument.cs
@@ -45,40 +45,37 @@ sealed class ReadOnlyDocumentLine : IDocumentLine
{
readonly ReadOnlyDocument doc;
readonly int lineNumber;
+ readonly int offset, endOffset;
public ReadOnlyDocumentLine(ReadOnlyDocument doc, int lineNumber)
{
this.doc = doc;
this.lineNumber = lineNumber;
+ this.offset = doc.GetStartOffset(lineNumber);
+ this.endOffset = doc.GetEndOffset(lineNumber);
}
public int Offset {
- get {
- return doc.GetStartOffset(lineNumber);
- }
+ get { return offset; }
}
public int Length {
- get {
- return doc.GetEndOffset(lineNumber) - doc.GetStartOffset(lineNumber);
- }
+ get { return endOffset - offset; }
}
public int EndOffset {
- get {
- return doc.GetEndOffset(lineNumber);
- }
+ get { return endOffset; }
}
public int TotalLength {
get {
- return doc.GetTotalEndOffset(lineNumber) - doc.GetStartOffset(lineNumber);
+ return doc.GetTotalEndOffset(lineNumber) - offset;
}
}
public int DelimiterLength {
get {
- return doc.GetTotalEndOffset(lineNumber) - doc.GetEndOffset(lineNumber);
+ return doc.GetTotalEndOffset(lineNumber) - endOffset;
}
}
@@ -248,7 +245,7 @@ public ReadOnlyDocumentTextAnchor(Location location, int offset)
public ITextBuffer CreateSnapshot()
{
- return this; // ReadOnlyDocument is immutable
+ return textBuffer; // textBuffer is immutable
}
public ITextBuffer CreateSnapshot(int offset, int length)

0 comments on commit 6a8c113

Please sign in to comment.