Skip to content

Commit 0f0ac50

Browse files
authored
Improve TypeRef equality comparer (#202)
***NO_CI***
1 parent 408a5e0 commit 0f0ac50

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

MetadataProcessor.Shared/Utility/TypeReferenceEqualityComparer.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@ public int GetHashCode(TypeReference obj)
7979
// provide an hash code based on the TypeSpec signature
8080
return xSignatureId;
8181
}
82-
else if (obj is GenericParameter)
82+
else if (obj is GenericParameter genericParam)
8383
{
8484
// provide an hash code based on the generic parameter position and type,
8585
// which is what makes it unique when comparing GenericParameter as a TypeReference
86-
var genericParam = obj as GenericParameter;
8786

88-
return genericParam.Position * 10 + (int)genericParam.Type;
87+
int hash = 17;
88+
hash = unchecked(hash * 31 + genericParam.DeclaringType?.MetadataToken.ToInt32() ?? 0);
89+
hash = unchecked(hash * 31 + genericParam.Position);
90+
hash = unchecked(hash * 31 + (int)genericParam.Type);
91+
92+
return hash;
8993
}
9094
else
9195
{

0 commit comments

Comments
 (0)