提交 fc628b5c 编写于 作者: S Sam Harwell

Avoid a capturing local variables on the GetOptionsAsync fast path

上级 cb579f24
......@@ -467,6 +467,7 @@ public Task<DocumentOptionSet> GetOptionsAsync(CancellationToken cancellationTok
return GetOptionsAsync(Project.Solution.Options, cancellationToken);
}
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/23582", AllowCaptures = false)]
internal Task<DocumentOptionSet> GetOptionsAsync(OptionSet solutionOptions, CancellationToken cancellationToken)
{
// TODO: we have this workaround since Solution.Options is not actually snapshot but just return Workspace.Options which violate snapshot model.
......@@ -475,17 +476,22 @@ internal Task<DocumentOptionSet> GetOptionsAsync(OptionSet solutionOptions, Canc
// snapshot model. once that is fixed, we can remove this workaround - https://github.com/dotnet/roslyn/issues/19284
if (_cachedOptions == null)
{
var newAsyncLazy = new AsyncLazy<DocumentOptionSet>(async c =>
{
var optionsService = Project.Solution.Workspace.Services.GetRequiredService<IOptionService>();
var documentOptionSet = await optionsService.GetUpdatedOptionSetForDocumentAsync(this, solutionOptions, c).ConfigureAwait(false);
return new DocumentOptionSet(documentOptionSet, Project.Language);
}, cacheResult: true);
Interlocked.CompareExchange(ref _cachedOptions, newAsyncLazy, comparand: null);
InitializeCachedOptions(solutionOptions, cancellationToken);
}
return _cachedOptions.GetValueAsync(cancellationToken);
}
private void InitializeCachedOptions(OptionSet solutionOptions, CancellationToken cancellationToken)
{
var newAsyncLazy = new AsyncLazy<DocumentOptionSet>(async c =>
{
var optionsService = Project.Solution.Workspace.Services.GetRequiredService<IOptionService>();
var documentOptionSet = await optionsService.GetUpdatedOptionSetForDocumentAsync(this, solutionOptions, c).ConfigureAwait(false);
return new DocumentOptionSet(documentOptionSet, Project.Language);
}, cacheResult: true);
Interlocked.CompareExchange(ref _cachedOptions, newAsyncLazy, comparand: null);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册