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

Reduce allocations in AbstractStructureTaggerProvider.GetMultiLineRegions #74619

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ private void ProcessSpans(
ImmutableArray<BlockSpan> spans)
{
var snapshot = snapshotSpan.Snapshot;
spans = GetMultiLineRegions(outliningService, spans, snapshot);
var multiLineSpans = GetMultiLineRegions(outliningService, spans, snapshot);
ToddGrun marked this conversation as resolved.
Show resolved Hide resolved

foreach (var span in spans)
foreach (var span in multiLineSpans)
{
var tag = new StructureTag(this, span, snapshot);
context.AddTag(new TagSpan<IContainerStructureTag>(span.TextSpan.ToSnapshotSpan(snapshot), tag));
Expand All @@ -226,12 +226,11 @@ protected override bool TagEquals(IContainerStructureTag tag1, IContainerStructu

private static bool s_exceptionReported = false;

private static ImmutableArray<BlockSpan> GetMultiLineRegions(
private static IEnumerable<BlockSpan> GetMultiLineRegions(
BlockStructureService service,
ImmutableArray<BlockSpan> regions, ITextSnapshot snapshot)
{
// Remove any spans that aren't multiline.
var multiLineRegions = ArrayBuilder<BlockSpan>.GetInstance();
foreach (var region in regions)
{
if (region.TextSpan.Length > 0)
Expand Down Expand Up @@ -262,12 +261,10 @@ private static ImmutableArray<BlockSpan> GetMultiLineRegions(
var endLine = snapshot.GetLineNumberFromPosition(region.TextSpan.End);
if (startLine != endLine)
{
multiLineRegions.Add(region);
yield return region;
}
}
}

return multiLineRegions.ToImmutableAndFree();
}

#region Creating Preview Buffers
Expand Down
Loading