Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify (Large/Source)Text.ParseLineStart to specify an initial capacity for line count #73701

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 1 deletion src/Compilers/Core/Portable/Text/LargeText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ private SegmentedList<int> ParseLineStarts()
var position = 0;
var index = 0;
var lastCr = -1;
var list = new SegmentedList<int>();
// Initial line capacity estimated at 64 chars / line. This value was obtained by
// looking at ratios in large files in the roslyn repo.
var list = new SegmentedList<int>(Length / 64);
ToddGrun marked this conversation as resolved.
Show resolved Hide resolved

// The following loop goes through every character in the text. It is highly
// performance critical, and thus inlines knowledge about common line breaks
Expand Down
4 changes: 3 additions & 1 deletion src/Compilers/Core/Portable/Text/SourceText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,9 @@ private SegmentedList<int> ParseLineStarts()
return [0];
}

var lineStarts = new SegmentedList<int>()
// Initial line capacity estimated at 64 chars / line. This value was obtained by
// looking at ratios in large files in the roslyn repo.
var lineStarts = new SegmentedList<int>(Length / 64)
{
0 // there is always the first line
};
Expand Down