Skip to content

Commit 41d8d32

Browse files
committed
C#: Address review comment: Make dictionary type more specific.
1 parent ead9167 commit 41d8d32

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

csharp/extractor/Semmle.Extraction/Context.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public Entity CreateEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> fact
6060
/// <param name="factory">The entity factory.</param>
6161
/// <param name="init">The initializer for the entity.</param>
6262
/// <returns>The new/existing entity.</returns>
63-
public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init) where Entity : ICachedEntity
63+
public Entity CreateEntityFromSymbol<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init)
64+
where Entity : ICachedEntity
65+
where Type: ISymbol
6466
{
6567
return init == null ? CreateEntity2(factory, init) : CreateNonNullEntity(factory, init, symbolEntityCache);
6668
}
@@ -149,8 +151,9 @@ private void CheckEntityHasUniqueLabel(string id, ICachedEntity entity)
149151
private Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init) where Entity : ICachedEntity
150152
=> CreateNonNullEntity(factory, init, objectEntityCache);
151153

152-
153-
private Entity CreateNonNullEntity<Type, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<object, ICachedEntity> dictionary) where Entity : ICachedEntity
154+
private Entity CreateNonNullEntity<Type, Src, Entity>(ICachedEntityFactory<Type, Entity> factory, Type init, IDictionary<Src, ICachedEntity> dictionary)
155+
where Entity : ICachedEntity
156+
where Type : Src
154157
{
155158
if (dictionary.TryGetValue(init, out var cached))
156159
return (Entity)cached;
@@ -215,17 +218,9 @@ public void AddFreshLabel(IEntity entity)
215218
#if DEBUG_LABELS
216219
readonly Dictionary<string, ICachedEntity> idLabelCache = new Dictionary<string, ICachedEntity>();
217220
#endif
218-
class SymbolComparer : IEqualityComparer<object>
219-
{
220-
IEqualityComparer<ISymbol> comparer = SymbolEqualityComparer.IncludeNullability;
221-
222-
bool IEqualityComparer<object>.Equals(object x, object y) => comparer.Equals((ISymbol)x, (ISymbol)y);
223-
224-
int IEqualityComparer<object>.GetHashCode(object obj) => comparer.GetHashCode((ISymbol)obj);
225-
}
226221

227222
readonly IDictionary<object, ICachedEntity> objectEntityCache = new Dictionary<object, ICachedEntity>();
228-
readonly IDictionary<object, ICachedEntity> symbolEntityCache = new Dictionary<object, ICachedEntity>(10000, new SymbolComparer());
223+
readonly IDictionary<ISymbol, ICachedEntity> symbolEntityCache = new Dictionary<ISymbol, ICachedEntity>(10000, SymbolEqualityComparer.IncludeNullability);
229224
readonly Dictionary<ICachedEntity, Label> entityLabelCache = new Dictionary<ICachedEntity, Label>();
230225
readonly HashSet<Label> extractedGenerics = new HashSet<Label>();
231226

0 commit comments

Comments
 (0)