Skip to content

Commit

Permalink
Fixed bug introduced in b7b12d3 (Reduce memory usage when dealing wit…
Browse files Browse the repository at this point in the history
…h long lines and word-wrapping)
  • Loading branch information
dgrunwald committed Mar 10, 2011
1 parent 41b10e9 commit b4f6f3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,29 @@ void IBuiltinElementGenerator.FetchOptions(TextEditorOptions options)
this.RequireControlModifierForClick = options.RequireControlModifierForHyperlinkClick;
}

Match GetMatch(int startOffset)
Match GetMatch(int startOffset, out int matchOffset)
{
int endOffset = CurrentContext.VisualLine.LastDocumentLine.EndOffset;
StringSegment relevantText = CurrentContext.GetText(startOffset, endOffset - startOffset);
return linkRegex.Match(relevantText.Text, relevantText.Offset, relevantText.Count);
Match m = linkRegex.Match(relevantText.Text, relevantText.Offset, relevantText.Count);
matchOffset = m.Success ? m.Index - relevantText.Offset + startOffset : -1;
return m;
}

/// <inheritdoc/>
public override int GetFirstInterestedOffset(int startOffset)
{
Match m = GetMatch(startOffset);
return m.Success ? startOffset + m.Index : -1;
int matchOffset;
GetMatch(startOffset, out matchOffset);
return matchOffset;
}

/// <inheritdoc/>
public override VisualLineElement ConstructElement(int offset)
{
Match m = GetMatch(offset);
if (m.Success && m.Index == 0) {
int matchOffset;
Match m = GetMatch(offset, out matchOffset);
if (m.Success && matchOffset == offset) {
Uri uri = GetUriFromMatch(m);
if (uri == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ public override int GetFirstInterestedOffset(int startOffset)
DocumentLine endLine = CurrentContext.VisualLine.LastDocumentLine;
StringSegment relevantText = CurrentContext.GetText(startOffset, endLine.EndOffset - startOffset);

int endPos = relevantText.Offset + relevantText.Count;
for (int i = relevantText.Offset; i < endPos; i++) {
char c = relevantText.Text[i];
for (int i = 0; i < relevantText.Count; i++) {
char c = relevantText.Text[relevantText.Offset + i];
switch (c) {
case ' ':
if (ShowSpaces)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ void PerformVisualElementConstruction(VisualLineElementGenerator[] generators)
askInterestOffset = 0;
offset += element.DocumentLength;
if (offset > currentLineEnd) {
LastDocumentLine = document.GetLineByOffset(offset);
currentLineEnd = LastDocumentLine.Offset + LastDocumentLine.Length;
DocumentLine newEndLine = document.GetLineByOffset(offset);
if (newEndLine == this.LastDocumentLine) {
throw new InvalidOperationException(
"The VisualLineElementGenerator " + g.GetType().Name +
" produced an element which ends within the line delimiter");
}
currentLineEnd = newEndLine.Offset + newEndLine.Length;
this.LastDocumentLine = newEndLine;
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;

Expand Down

0 comments on commit b4f6f3a

Please sign in to comment.