-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46740 from jasonmalinowski/add-editorconfig-cache
Add a cache for AnalyzerConfigSets
- Loading branch information
Showing
2 changed files
with
49 additions
and
11 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/Workspaces/Core/Portable/Workspace/Solution/CachingAnalyzerConfigSet.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace Microsoft.CodeAnalysis | ||
{ | ||
internal sealed class CachingAnalyzerConfigSet | ||
{ | ||
private readonly ConcurrentDictionary<string, AnalyzerConfigOptionsResult> _sourcePathToResult = new ConcurrentDictionary<string, AnalyzerConfigOptionsResult>(); | ||
private readonly Func<string, AnalyzerConfigOptionsResult> _computeFunction; | ||
private readonly AnalyzerConfigSet _underlyingSet; | ||
|
||
public CachingAnalyzerConfigSet(AnalyzerConfigSet underlyingSet) | ||
{ | ||
_underlyingSet = underlyingSet; | ||
_computeFunction = _underlyingSet.GetOptionsForSourcePath; | ||
} | ||
|
||
public AnalyzerConfigOptionsResult GetOptionsForSourcePath(string sourcePath) | ||
{ | ||
return _sourcePathToResult.GetOrAdd(sourcePath, _computeFunction); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters