11using System ;
2+ using System . Collections . Concurrent ;
23using Microsoft . CodeAnalysis ;
34using Microsoft . CodeAnalysis . CSharp ;
45using Microsoft . CodeAnalysis . CSharp . Syntax ;
1415[ Generator ]
1516public class SQLiteFastColumnSetterGenerator : IIncrementalGenerator
1617{
18+ private static ConcurrentDictionary < INamedTypeSymbol , bool > cachedHasSqliteAttribute = new ( ) ;
19+ private static ConcurrentDictionary < INamedTypeSymbol , bool > cachedHasTableAttribute = new ( ) ;
1720 private static List < string > SQLitePropertyAttributes = default ! ;
1821 private static ImmutableHashSet < string > SQLitePropertyFullAttributes = default ! ;
1922
@@ -166,15 +169,23 @@ static bool HasBaseClass (ClassDeclarationSyntax classDecl)
166169
167170 private static bool HasSQLiteAttribute ( INamedTypeSymbol ? classSymbol )
168171 {
172+ if ( classSymbol != null && cachedHasSqliteAttribute . TryGetValue ( classSymbol , out var result ) ) {
173+ return result ;
174+ }
175+
169176 while ( true ) {
170177 if ( classSymbol == null || classSymbol . SpecialType == SpecialType . System_Object ) {
178+ if ( classSymbol != null ) {
179+ cachedHasSqliteAttribute [ classSymbol ] = false ;
180+ }
171181 return false ;
172182 }
173183
174184 var members = classSymbol . GetMembers ( ) ;
175185 foreach ( var member in members ) {
176186 if ( member . GetAttributes ( ) . Any ( attr => IsSQLiteAttribute ( attr . AttributeClass ) ) )
177187 {
188+ cachedHasSqliteAttribute [ classSymbol ] = true ;
178189 return true ;
179190 }
180191 }
@@ -185,14 +196,24 @@ private static bool HasSQLiteAttribute (INamedTypeSymbol? classSymbol)
185196
186197 private static bool HasTableAttribute ( INamedTypeSymbol ? classSymbol )
187198 {
188- while ( true ) {
199+ if ( classSymbol != null && cachedHasTableAttribute . TryGetValue ( classSymbol , out var result ) ) {
200+ return result ;
201+ }
202+
203+ while ( true ) {
189204 if ( classSymbol == null || classSymbol . SpecialType == SpecialType . System_Object ) {
205+ if ( classSymbol != null ) {
206+ cachedHasTableAttribute [ classSymbol ] = false ;
207+ }
190208 return false ;
191209 }
192210
193211 var hasTableAttribute = classSymbol . GetAttributes ( )
194212 . Any ( attr => IsTableAttribute ( attr . AttributeClass ) ) ;
195- if ( hasTableAttribute ) return true ;
213+ if ( hasTableAttribute ) {
214+ cachedHasTableAttribute [ classSymbol ] = true ;
215+ return true ;
216+ }
196217
197218 classSymbol = classSymbol . BaseType ;
198219 }
0 commit comments