Skip to content

Commit

Permalink
Convert byte array key to type cache from static to instance bound (#305
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Arkatufus authored Mar 23, 2022
1 parent 28d3c58 commit f310df6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/Hyperion/Extensions/TypeEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@ public static bool IsOneDimensionalPrimitiveArray(this Type type)
return type.IsArray && type.GetArrayRank() == 1 && type.GetElementType().IsHyperionPrimitive();
}

private static readonly ConcurrentDictionary<ByteArrayKey, Type> TypeNameLookup =
new ConcurrentDictionary<ByteArrayKey, Type>(ByteArrayKeyComparer.Instance);

public static byte[] GetTypeManifest(IReadOnlyCollection<byte[]> fieldNames)
{
IEnumerable<byte> result = new[] { (byte)fieldNames.Count };
Expand All @@ -153,7 +150,7 @@ private static Type GetTypeFromManifestName(Stream stream, DeserializerSession s
{
var bytes = stream.ReadLengthEncodedByteArray(session);
var byteArr = ByteArrayKey.Create(bytes);
return TypeNameLookup.GetOrAdd(byteArr, b =>
return session.Serializer.TypeNameLookup.GetOrAdd(byteArr, b =>
{
var shortName = StringEx.FromUtf8Bytes(b.Bytes, 0, b.Bytes.Length);
var overrides = session.Serializer.Options.CrossFrameworkPackageNameOverrides;
Expand Down
3 changes: 3 additions & 0 deletions src/Hyperion/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class Serializer

public readonly SerializerOptions Options;

internal readonly ConcurrentDictionary<ByteArrayKey, Type> TypeNameLookup =
new ConcurrentDictionary<ByteArrayKey, Type>(ByteArrayKeyComparer.Instance);

public Serializer() : this(new SerializerOptions())
{
}
Expand Down

0 comments on commit f310df6

Please sign in to comment.