Skip to content

Commit

Permalink
Update TypeProvider.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Oct 15, 2023
1 parent c26162d commit 4186b7d
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/Draco.Compiler/Internal/Symbols/Metadata/TypeProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
Expand All @@ -21,7 +22,7 @@ internal sealed class TypeProvider : ISignatureTypeProvider<TypeSymbol, Symbol>,
private IntrinsicSymbols IntrinsicSymbols => this.compilation.IntrinsicSymbols;

private readonly Compilation compilation;
private readonly Dictionary<CacheKey, TypeSymbol> cache = new();
private readonly ConcurrentDictionary<CacheKey, TypeSymbol> cache = new();

public TypeProvider(Compilation compilation)
{
Expand Down Expand Up @@ -94,12 +95,7 @@ public TypeSymbol GetGenericTypeParameter(Symbol genericContext, int index)
public TypeSymbol GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
{
var key = new CacheKey(reader, handle);
if (!this.cache.TryGetValue(key, out var type))
{
type = this.BuildTypeFromDefinition(reader, handle, rawTypeKind);
this.cache.Add(key, type);
}
return type;
return this.cache.GetOrAdd(key, _ => this.BuildTypeFromDefinition(reader, handle, rawTypeKind));
}

private TypeSymbol BuildTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
Expand Down Expand Up @@ -137,12 +133,7 @@ private TypeSymbol BuildTypeFromDefinition(MetadataReader reader, TypeDefinition
public TypeSymbol GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
{
var key = new CacheKey(reader, handle);
if (!this.cache.TryGetValue(key, out var type))
{
type = this.BuildTypeFromReference(reader, handle, rawTypeKind);
this.cache.Add(key, type);
}
return type;
return this.cache.GetOrAdd(key, _ => this.BuildTypeFromReference(reader, handle, rawTypeKind));
}

private TypeSymbol BuildTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
Expand Down

0 comments on commit 4186b7d

Please sign in to comment.