Skip to content

Commit dadfad6

Browse files
committed
Remove AnalyzerExtensions.settingsCache
1 parent 128898e commit dadfad6

1 file changed

Lines changed: 1 addition & 47 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/AnalyzerExtensions.cs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace StyleCop.Analyzers
66
using System;
77
using System.Collections.Concurrent;
88
using System.Collections.Immutable;
9-
using System.Runtime.CompilerServices;
109
using System.Threading;
1110
using Microsoft.CodeAnalysis;
1211
using Microsoft.CodeAnalysis.Diagnostics;
@@ -27,9 +26,6 @@ internal static class AnalyzerExtensions
2726
private static Tuple<WeakReference<Compilation>, ConcurrentDictionary<SyntaxTree, bool>> generatedHeaderCache
2827
= Tuple.Create(new WeakReference<Compilation>(null), default(ConcurrentDictionary<SyntaxTree, bool>));
2928

30-
private static Tuple<WeakReference<Compilation>, StrongBox<StyleCopSettings>> settingsCache
31-
= Tuple.Create(new WeakReference<Compilation>(null), default(StrongBox<StyleCopSettings>));
32-
3329
/// <summary>
3430
/// Register an action to be executed at completion of parsing of a code document. A syntax tree action reports
3531
/// diagnostics about the <see cref="SyntaxTree"/> of a document.
@@ -96,40 +92,6 @@ public static ConcurrentDictionary<SyntaxTree, bool> GetOrCreateGeneratedDocumen
9692
return headerCache.Item2;
9793
}
9894

99-
/// <summary>
100-
/// Gets a <see cref="StrongBox{T}"/> which can store a <see cref="StyleCopSettings"/> instance to improve
101-
/// efficiency across multiple analyzers which examine settings.
102-
/// </summary>
103-
/// <param name="compilation">The compilation which the cache applies to.</param>
104-
/// <returns>A <see cref="StrongBox{T}"/> which can store a <see cref="StyleCopSettings"/> instance.</returns>
105-
public static StrongBox<StyleCopSettings> GetOrCreateStyleCopSettingsCache(this Compilation compilation)
106-
{
107-
var currentSettingsCache = settingsCache;
108-
109-
Compilation cachedCompilation;
110-
if (!currentSettingsCache.Item1.TryGetTarget(out cachedCompilation) || cachedCompilation != compilation)
111-
{
112-
var replacementCache = Tuple.Create(new WeakReference<Compilation>(compilation), new StrongBox<StyleCopSettings>(null));
113-
while (true)
114-
{
115-
var prior = Interlocked.CompareExchange(ref settingsCache, replacementCache, currentSettingsCache);
116-
if (prior == currentSettingsCache)
117-
{
118-
currentSettingsCache = replacementCache;
119-
break;
120-
}
121-
122-
currentSettingsCache = prior;
123-
if (currentSettingsCache.Item1.TryGetTarget(out cachedCompilation) && cachedCompilation == compilation)
124-
{
125-
break;
126-
}
127-
}
128-
}
129-
130-
return currentSettingsCache.Item2;
131-
}
132-
13395
/// <summary>
13496
/// Register an action to be executed at completion of semantic analysis of a <see cref="SyntaxNode"/> with an
13597
/// appropriate kind. A syntax node action can report diagnostics about a <see cref="SyntaxNode"/>, and can also
@@ -222,7 +184,6 @@ public static void RegisterSyntaxNodeActionHonorExclusions<TLanguageKindEnum>(th
222184
{
223185
Compilation compilation = context.Compilation;
224186
ConcurrentDictionary<SyntaxTree, bool> cache = GetOrCreateGeneratedDocumentCache(compilation);
225-
StrongBox<StyleCopSettings> settingsCache = GetOrCreateStyleCopSettingsCache(compilation);
226187

227188
context.RegisterSyntaxNodeAction(
228189
c =>
@@ -236,14 +197,7 @@ public static void RegisterSyntaxNodeActionHonorExclusions<TLanguageKindEnum>(th
236197
// MSBuild metadata, if analyzers have access to it.
237198
//// TODO: code here
238199

239-
StyleCopSettings settings = settingsCache.Value;
240-
if (settings == null)
241-
{
242-
StyleCopSettings updatedSettings = SettingsHelper.GetStyleCopSettings(c.Options, c.CancellationToken);
243-
StyleCopSettings previous = Interlocked.CompareExchange(ref settingsCache.Value, updatedSettings, null);
244-
settings = previous ?? updatedSettings;
245-
}
246-
200+
StyleCopSettings settings = context.GetStyleCopSettings(c.Options, c.CancellationToken);
247201
action(c, settings);
248202
},
249203
syntaxKinds);

0 commit comments

Comments
 (0)