提交 c86184ba 编写于 作者: D Dustin Campbell

Reuse a single StringBuilder for all items when building C# cref completion items

上级 dc866cd2
......@@ -138,22 +138,30 @@ private IEnumerable<ISymbol> GetOperatorsAndIndexers(SyntaxToken token, Semantic
private async Task<IEnumerable<CompletionItem>> CreateItemsAsync(
Workspace workspace, SemanticModel semanticModel, int textChangeSpanPosition, IEnumerable<ISymbol> symbols, SyntaxToken token, CancellationToken cancellationToken)
{
var items = new List<CompletionItem>();
var builder = SharedPools.Default<StringBuilder>().AllocateAndClear();
try
{
var items = new List<CompletionItem>();
foreach (var symbol in symbols)
{
var item = await CreateItemAsync(workspace, semanticModel, textChangeSpanPosition, symbol, token, builder, cancellationToken).ConfigureAwait(false);
items.Add(item);
builder.Clear();
}
foreach (var symbol in symbols)
return items;
}
finally
{
var item = await CreateItemAsync(workspace, semanticModel, textChangeSpanPosition, symbol, token, cancellationToken).ConfigureAwait(false);
items.Add(item);
SharedPools.Default<StringBuilder>().ClearAndFree(builder);
}
return items;
}
private async Task<CompletionItem> CreateItemAsync(
Workspace workspace, SemanticModel semanticModel, int textChangeSpanPosition, ISymbol symbol, SyntaxToken token, CancellationToken cancellationToken)
Workspace workspace, SemanticModel semanticModel, int textChangeSpanPosition, ISymbol symbol, SyntaxToken token, StringBuilder builder, CancellationToken cancellationToken)
{
var builder = SharedPools.Default<StringBuilder>().AllocateAndClear();
int tokenPosition = token.SpanStart;
if (symbol is INamespaceOrTypeSymbol && token.IsKind(SyntaxKind.DotToken))
......@@ -207,8 +215,6 @@ private IEnumerable<ISymbol> GetOperatorsAndIndexers(SyntaxToken token, Semantic
.Replace('>', '}')
.ToString();
SharedPools.Default<StringBuilder>().ClearAndFree(builder);
var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
return new Item(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册