Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Compilers/Core/Portable/Text/SourceText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -966,12 +966,12 @@ public override TextLine this[int index]
int start = _lineStarts[index];
if (index == _lineStarts.Count - 1)
{
return TextLine.FromSpan(_text, TextSpan.FromBounds(start, _text.Length));
return TextLine.FromKnownSpan(_text, TextSpan.FromBounds(start, _text.Length));
}
else
{
int end = _lineStarts[index + 1];
return TextLine.FromSpan(_text, TextSpan.FromBounds(start, end));
return TextLine.FromKnownSpan(_text, TextSpan.FromBounds(start, end));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/Compilers/Core/Portable/Text/TextLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public static TextLine FromSpan(SourceText text, TextSpan span)
}
}

// Do not use unless you are certain the span you are passing in is valid!
// This was added to allow SourceText's indexer to directly create TextLines
// without the performance implications of calling FromSpan.
internal static TextLine FromKnownSpan(SourceText text, TextSpan span)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an assert to verify the span in debug mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, will do!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you consider say FromSpanUnsafe as a name? Basically and indicator to the caller that they're playing with fire with this method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a good idea, changed.

{
return new TextLine(text, span.Start, span.End);
}

/// <summary>
/// Gets the source text.
/// </summary>
Expand Down