@@ -75,7 +75,7 @@ public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, En
7575 where Entity : ICachedEntity
7676 where Type : ISymbol
7777 {
78- return init == null ? CreateEntity2 ( factory , init ) : CreateNonNullEntity ( factory , init ) ;
78+ return init == null ? CreateEntity2 ( factory , init ) : CreateNonNullEntity ( factory , init , symbolEntityCache ) ;
7979 }
8080
8181 // A recursion guard against writing to the trap file whilst writing an id to the trap file.
@@ -161,11 +161,11 @@ private void CheckEntityHasUniqueLabel(string id, ICachedEntity entity)
161161
162162 public Entity CreateNonNullEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init )
163163 where Entity : ICachedEntity
164+ where Type : notnull
164165 => CreateNonNullEntity ( factory , init , objectEntityCache ) ;
165166
166- private Entity CreateNonNullEntity < Type , Src , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init , IDictionary < Src , ICachedEntity > dictionary )
167+ private Entity CreateNonNullEntity < Type , Entity > ( ICachedEntityFactory < Type , Entity > factory , Type init , IDictionary < object , ICachedEntity > dictionary )
167168 where Entity : ICachedEntity
168- where Type : Src
169169 {
170170 if ( init is null ) throw new ArgumentException ( "Unexpected null value" , nameof ( init ) ) ;
171171
@@ -233,8 +233,18 @@ public void AddFreshLabel(IEntity entity)
233233 readonly Dictionary < string , ICachedEntity > idLabelCache = new Dictionary < string , ICachedEntity > ( ) ;
234234#endif
235235
236+ // Adaptor to convert IEqualityComparer<ISymbol> to IEqualityComparer<object>
237+ class SymbolComparer : IEqualityComparer < object >
238+ {
239+ IEqualityComparer < ISymbol > comparer = SymbolEqualityComparer . IncludeNullability ;
240+
241+ bool IEqualityComparer < object > . Equals ( object ? x , object ? y ) => comparer . Equals ( x as ISymbol , y as ISymbol ) ;
242+
243+ int IEqualityComparer < object > . GetHashCode ( object obj ) => comparer . GetHashCode ( ( ISymbol ) obj ) ;
244+ }
245+
236246 readonly IDictionary < object , ICachedEntity > objectEntityCache = new Dictionary < object , ICachedEntity > ( ) ;
237- readonly IDictionary < ISymbol , ICachedEntity > symbolEntityCache = new Dictionary < ISymbol , ICachedEntity > ( 10000 , SymbolEqualityComparer . IncludeNullability ) ;
247+ readonly IDictionary < object , ICachedEntity > symbolEntityCache = new Dictionary < object , ICachedEntity > ( 10000 , new SymbolComparer ( ) ) ;
238248 readonly Dictionary < ICachedEntity , Label > entityLabelCache = new Dictionary < ICachedEntity , Label > ( ) ;
239249 readonly HashSet < Label > extractedGenerics = new HashSet < Label > ( ) ;
240250
0 commit comments