Skip to content

Commit 4195f16

Browse files
committed
Explicitly compare MaybeType objects by name
1 parent 8e8c3f3 commit 4195f16

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/runtime/ClassManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Diagnostics;
44
using System.Linq;
55
using System.Reflection;
6-
using System.Runtime.InteropServices;
76
using System.Security;
87

98
using Python.Runtime.StateSerialization;
@@ -33,7 +32,9 @@ internal class ClassManager
3332
BindingFlags.Public |
3433
BindingFlags.NonPublic;
3534

36-
internal static Dictionary<MaybeType, ReflectedClrType> cache = new(capacity: 128);
35+
internal static Dictionary<MaybeType, ReflectedClrType> cache = new(
36+
capacity: 128, comparer: new MaybeTypeComparer()
37+
);
3738
private static readonly Type dtype;
3839

3940
private ClassManager()

src/runtime/StateSerialization/MaybeType.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Runtime.Serialization;
44
using System.Runtime.Serialization.Formatters.Binary;
55
using System.IO;
6+
using System.Collections.Generic;
67

78
namespace Python.Runtime
89
{
@@ -61,4 +62,12 @@ public void GetObjectData(SerializationInfo serializationInfo, StreamingContext
6162
serializationInfo.AddValue(SerializationName, name);
6263
}
6364
}
65+
66+
internal class MaybeTypeComparer : IEqualityComparer<MaybeType>
67+
{
68+
public bool Equals (MaybeType lhs, MaybeType rhs) =>
69+
lhs.Name == rhs.Name;
70+
71+
public int GetHashCode(MaybeType t) => t.Name.GetHashCode();
72+
}
6473
}

0 commit comments

Comments
 (0)