diff --git a/src/Meziantou.Analyzer/Internals/AwaitableTypes.cs b/src/Meziantou.Analyzer/Internals/AwaitableTypes.cs index e84d58931..bea041024 100644 --- a/src/Meziantou.Analyzer/Internals/AwaitableTypes.cs +++ b/src/Meziantou.Analyzer/Internals/AwaitableTypes.cs @@ -1,3 +1,4 @@ +using System.Collections.Concurrent; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Operations; @@ -6,6 +7,7 @@ internal sealed class AwaitableTypes { private readonly INamedTypeSymbol[] _taskOrValueTaskSymbols; private readonly Compilation _compilation; + private readonly ConcurrentDictionary _isAwaitableCache = new(SymbolEqualityComparer.Default); public AwaitableTypes(Compilation compilation) { @@ -80,6 +82,11 @@ public bool IsAwaitable(ITypeSymbol? symbol) if (symbol is null) return false; + return _isAwaitableCache.GetOrAdd(symbol, IsAwaitableCore); + } + + private bool IsAwaitableCore(ITypeSymbol symbol) + { if (INotifyCompletionSymbol is null) return false;