Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align native SpecializeComparer with managed ComparerHelpers #38681

Merged
merged 2 commits into from
Jul 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 14 additions & 32 deletions src/coreclr/src/vm/compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4803,7 +4803,7 @@ static BOOL CanSatisfyConstraints(Instantiation typicalInst, Instantiation candi


//
// This method has duplicated logic from bcl\system\collections\generic\comparer.cs
// This method has duplicated logic from coreclr\src\System.Private.CoreLib\src\System\Collections\Generic\ComparerHelpers.cs
//
static void SpecializeComparer(SString& ss, Instantiation& inst)
{
Expand Down Expand Up @@ -4843,33 +4843,21 @@ static void SpecializeComparer(SString& ss, Instantiation& inst)
CorElementType et = elemTypeHnd.GetVerifierCorElementType();
if (et == ELEMENT_TYPE_I1 ||
et == ELEMENT_TYPE_I2 ||
et == ELEMENT_TYPE_I4)
{
ss.Set(W("System.Collections.Generic.Int32EnumComparer`1"));
return;
}
if (et == ELEMENT_TYPE_U1 ||
et == ELEMENT_TYPE_I4 ||
et == ELEMENT_TYPE_I8 ||
et == ELEMENT_TYPE_U1 ||
et == ELEMENT_TYPE_U2 ||
et == ELEMENT_TYPE_U4)
{
ss.Set(W("System.Collections.Generic.UInt32EnumComparer`1"));
return;
}
if (et == ELEMENT_TYPE_I8)
{
ss.Set(W("System.Collections.Generic.Int64EnumComparer`1"));
return;
}
if (et == ELEMENT_TYPE_U8)
et == ELEMENT_TYPE_U4 ||
et == ELEMENT_TYPE_U8)
{
ss.Set(W("System.Collections.Generic.UInt64EnumComparer`1"));
ss.Set(W("System.Collections.Generic.EnumComparer`1"));
tkp1n marked this conversation as resolved.
Show resolved Hide resolved
return;
}
}
}

//
// This method has duplicated logic from bcl\system\collections\generic\equalitycomparer.cs
// This method has duplicated logic from coreclr\src\System.Private.CoreLib\src\System\Collections\Generic\ComparerHelpers.cs
// and matching logic in jitinterface.cpp
//
static void SpecializeEqualityComparer(SString& ss, Instantiation& inst)
Expand Down Expand Up @@ -4907,25 +4895,19 @@ static void SpecializeEqualityComparer(SString& ss, Instantiation& inst)

if (elemTypeHnd.IsEnum())
{
// Note: We have different comparers for Short and SByte because for those types we need to make sure we call GetHashCode on the actual underlying type as the
// implementation of GetHashCode is more complex than for the other types.
CorElementType et = elemTypeHnd.GetVerifierCorElementType();
if (et == ELEMENT_TYPE_I4 ||
et == ELEMENT_TYPE_U4 ||
et == ELEMENT_TYPE_U2 ||
if (et == ELEMENT_TYPE_I1 ||
et == ELEMENT_TYPE_I2 ||
et == ELEMENT_TYPE_I4 ||
et == ELEMENT_TYPE_I8 ||
et == ELEMENT_TYPE_U1 ||
et == ELEMENT_TYPE_I1)
et == ELEMENT_TYPE_U2 ||
et == ELEMENT_TYPE_U4 ||
et == ELEMENT_TYPE_U8)
{
ss.Set(W("System.Collections.Generic.EnumEqualityComparer`1"));
return;
}
else if (et == ELEMENT_TYPE_I8 ||
et == ELEMENT_TYPE_U8)
{
ss.Set(W("System.Collections.Generic.LongEnumEqualityComparer`1"));
return;
}
}
}

Expand Down