Skip to content

Commit f310df6

Browse files
authored
Convert byte array key to type cache from static to instance bound (#305)
1 parent 28d3c58 commit f310df6

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Hyperion/Extensions/TypeEx.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ public static bool IsOneDimensionalPrimitiveArray(this Type type)
133133
return type.IsArray && type.GetArrayRank() == 1 && type.GetElementType().IsHyperionPrimitive();
134134
}
135135

136-
private static readonly ConcurrentDictionary<ByteArrayKey, Type> TypeNameLookup =
137-
new ConcurrentDictionary<ByteArrayKey, Type>(ByteArrayKeyComparer.Instance);
138-
139136
public static byte[] GetTypeManifest(IReadOnlyCollection<byte[]> fieldNames)
140137
{
141138
IEnumerable<byte> result = new[] { (byte)fieldNames.Count };
@@ -153,7 +150,7 @@ private static Type GetTypeFromManifestName(Stream stream, DeserializerSession s
153150
{
154151
var bytes = stream.ReadLengthEncodedByteArray(session);
155152
var byteArr = ByteArrayKey.Create(bytes);
156-
return TypeNameLookup.GetOrAdd(byteArr, b =>
153+
return session.Serializer.TypeNameLookup.GetOrAdd(byteArr, b =>
157154
{
158155
var shortName = StringEx.FromUtf8Bytes(b.Bytes, 0, b.Bytes.Length);
159156
var overrides = session.Serializer.Options.CrossFrameworkPackageNameOverrides;

src/Hyperion/Serializer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class Serializer
3434

3535
public readonly SerializerOptions Options;
3636

37+
internal readonly ConcurrentDictionary<ByteArrayKey, Type> TypeNameLookup =
38+
new ConcurrentDictionary<ByteArrayKey, Type>(ByteArrayKeyComparer.Instance);
39+
3740
public Serializer() : this(new SerializerOptions())
3841
{
3942
}

0 commit comments

Comments
 (0)