提交 65cc6157 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14088 from CyrusNajmabadi/useArrayBuilderPAttern

Finish teh work to use pooled array builders.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Structure;
......@@ -15,7 +16,7 @@ public class CommentTests : AbstractSyntaxStructureProviderTests
{
protected override string LanguageName => LanguageNames.CSharp;
internal override async Task<BlockSpan[]> GetBlockSpansAsync(Document document, int position)
internal override async Task<ImmutableArray<BlockSpan>> GetBlockSpansWorkerAsync(Document document, int position)
{
var root = await document.GetSyntaxRootAsync();
var trivia = root.FindTrivia(position, findInsideTrivia: true);
......@@ -24,15 +25,15 @@ internal override async Task<BlockSpan[]> GetBlockSpansAsync(Document document,
if (token.LeadingTrivia.Contains(trivia))
{
return CSharpStructureHelpers.CreateCommentBlockSpan(token.LeadingTrivia).ToArray();
return CSharpStructureHelpers.CreateCommentBlockSpan(token.LeadingTrivia);
}
else if (token.TrailingTrivia.Contains(trivia))
{
return CSharpStructureHelpers.CreateCommentBlockSpan(token.TrailingTrivia).ToArray();
return CSharpStructureHelpers.CreateCommentBlockSpan(token.TrailingTrivia);
}
else
{
return Contract.FailWithReturn<BlockSpan[]>();
return Contract.FailWithReturn<ImmutableArray<BlockSpan>>();
}
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -20,12 +21,11 @@ public class InvalidIdentifierStructureTests : AbstractSyntaxStructureProviderTe
protected override string LanguageName => LanguageNames.CSharp;
protected override string WorkspaceKind => CodeAnalysis.WorkspaceKind.MetadataAsSource;
internal override async Task<BlockSpan[]> GetBlockSpansAsync(Document document, int position)
internal override async Task<ImmutableArray<BlockSpan>> GetBlockSpansWorkerAsync(Document document, int position)
{
var outliningService = document.Project.LanguageServices.GetService<BlockStructureService>();
return (await outliningService.GetBlockStructureAsync(document, CancellationToken.None))
.Spans.WhereNotNull().ToArray();
return (await outliningService.GetBlockStructureAsync(document, CancellationToken.None)).Spans;
}
[WorkItem(1174405, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1174405")]
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Structure;
using Roslyn.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.UnitTests.Structure
......@@ -15,7 +13,7 @@ public abstract class AbstractSyntaxNodeStructureProviderTests<TSyntaxNode> : Ab
{
internal abstract AbstractSyntaxStructureProvider CreateProvider();
internal sealed override async Task<BlockSpan[]> GetBlockSpansAsync(Document document, int position)
internal sealed override async Task<ImmutableArray<BlockSpan>> GetBlockSpansWorkerAsync(Document document, int position)
{
var root = await document.GetSyntaxRootAsync(CancellationToken.None);
var token = root.FindToken(position, findInsideTrivia: true);
......@@ -41,7 +39,7 @@ internal sealed override async Task<BlockSpan[]> GetBlockSpansAsync(Document doc
outliner.CollectBlockSpans(document, node, actualRegions, CancellationToken.None);
// TODO: Determine why we get null outlining spans.
return actualRegions.WhereNotNull().ToArray();
return actualRegions.ToImmutableAndFree();
}
}
}
}
\ No newline at end of file
......@@ -2,11 +2,13 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Structure;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.UnitTests.Structure
......@@ -17,7 +19,13 @@ public abstract class AbstractSyntaxStructureProviderTests
protected virtual string WorkspaceKind => TestWorkspace.WorkspaceName;
internal abstract Task<BlockSpan[]> GetBlockSpansAsync(Document document, int position);
private async Task<ImmutableArray<BlockSpan>> GetBlockSpansAsync(Document document, int position)
{
var spans = await GetBlockSpansWorkerAsync(document, position);
return spans.WhereNotNull().ToImmutableArray();
}
internal abstract Task<ImmutableArray<BlockSpan>> GetBlockSpansWorkerAsync(Document document, int position);
protected async Task VerifyBlockSpansAsync(string markupCode, params Tuple<string, string, string, bool, bool>[] expectedRegionData)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Structure;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Editor.UnitTests.Structure
{
......@@ -13,9 +11,9 @@ public abstract class AbstractSyntaxTriviaStructureProviderTests : AbstractSynta
{
internal abstract AbstractSyntaxStructureProvider CreateProvider();
internal sealed override async Task<BlockSpan[]> GetBlockSpansAsync(Document document, int position)
internal sealed override async Task<ImmutableArray<BlockSpan>> GetBlockSpansWorkerAsync(Document document, int position)
{
var root = await document.GetSyntaxRootAsync(CancellationToken.None);
var root = await document.GetSyntaxRootAsync();
var trivia = root.FindTrivia(position, findInsideTrivia: true);
var outliner = CreateProvider();
......@@ -23,7 +21,7 @@ internal sealed override async Task<BlockSpan[]> GetBlockSpansAsync(Document doc
outliner.CollectBlockSpans(document, trivia, actualRegions, CancellationToken.None);
// TODO: Determine why we get null outlining spans.
return actualRegions.WhereNotNull().ToArray();
return actualRegions.ToImmutableAndFree();
}
}
}
}
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Structure
Imports Microsoft.CodeAnalysis.Structure
Imports Microsoft.CodeAnalysis.VisualBasic.Structure
......@@ -14,18 +15,18 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining
End Get
End Property
Friend Overrides Async Function GetBlockSpansAsync(document As Document, position As Integer) As Task(Of BlockSpan())
Friend Overrides Async Function GetBlockSpansWorkerAsync(document As Document, position As Integer) As Task(Of ImmutableArray(Of BlockSpan))
Dim root = Await document.GetSyntaxRootAsync()
Dim trivia = root.FindTrivia(position, findInsideTrivia:=True)
Dim token = trivia.Token
If token.LeadingTrivia.Contains(trivia) Then
Return CreateCommentsRegions(token.LeadingTrivia).ToArray()
Return CreateCommentsRegions(token.LeadingTrivia)
ElseIf token.TrailingTrivia.Contains(trivia) Then
Return CreateCommentsRegions(token.TrailingTrivia).ToArray()
Return CreateCommentsRegions(token.TrailingTrivia)
Else
Return Contract.FailWithReturn(Of BlockSpan())()
Return Contract.FailWithReturn(Of ImmutableArray(Of BlockSpan))()
End If
End Function
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Structure
Imports Microsoft.CodeAnalysis.Structure
......@@ -24,13 +25,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining.Metadata
End Get
End Property
Friend Overrides Async Function GetBlockSpansAsync(document As Document, position As Integer) As Task(Of BlockSpan())
Friend Overrides Async Function GetBlockSpansWorkerAsync(document As Document, position As Integer) As Task(Of ImmutableArray(Of BlockSpan))
Dim outliningService = document.Project.LanguageServices.GetService(Of BlockStructureService)()
Return (Await outliningService.GetBlockStructureAsync(document, CancellationToken.None)) _
.Spans _
.WhereNotNull() _
.ToArray()
Return (Await outliningService.GetBlockStructureAsync(document, CancellationToken.None)).Spans
End Function
<WorkItem(1174405, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1174405")>
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.Threading
Imports Microsoft.CodeAnalysis.Editor.UnitTests.Structure
Imports Microsoft.CodeAnalysis.Structure
......@@ -14,13 +15,10 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining
End Get
End Property
Friend Overrides Async Function GetBlockSpansAsync(document As Document, position As Integer) As Task(Of BlockSpan())
Friend Overrides Async Function GetBlockSpansWorkerAsync(document As Document, position As Integer) As Task(Of ImmutableArray(Of BlockSpan))
Dim outliningService = document.Project.LanguageServices.GetService(Of BlockStructureService)()
Return (Await outliningService.GetBlockStructureAsync(document, CancellationToken.None)) _
.Spans _
.WhereNotNull() _
.ToArray()
Return (Await outliningService.GetBlockStructureAsync(document, CancellationToken.None)).Spans
End Function
<Fact, Trait(Traits.Feature, Traits.Features.Outlining)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册