Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ namespace System.Collections.Generic
{
public abstract partial class Comparer<T> : IComparer, IComparer<T>
{
// This method is special cased in R2R, with its implementation replaced by IL helper
Comment thread
BrzVlad marked this conversation as resolved.
[Intrinsic]
private static Comparer<T> Create() => (Comparer<T>)ComparerHelpers.CreateDefaultComparer(typeof(T));

// To minimize generic instantiation overhead of creating the comparer per type, we keep the generic portion of the code as small
// as possible and define most of the creation logic in a non-generic class.
public static Comparer<T> Default { [Intrinsic] get; } = (Comparer<T>)ComparerHelpers.CreateDefaultComparer(typeof(T));
public static Comparer<T> Default { [Intrinsic] get; } = Create();
}

internal sealed partial class EnumComparer<T> : Comparer<T> where T : struct, Enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ namespace System.Collections.Generic
{
public abstract partial class EqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
{
// This method is special cased in R2R, with its implementation replaced by IL helper
Comment thread
BrzVlad marked this conversation as resolved.
[Intrinsic]
private static EqualityComparer<T> Create() => (EqualityComparer<T>)ComparerHelpers.CreateDefaultEqualityComparer(typeof(T));

// To minimize generic instantiation overhead of creating the comparer per type, we keep the generic portion of the code as small
// as possible and define most of the creation logic in a non-generic class.
public static EqualityComparer<T> Default { [Intrinsic] get; } = (EqualityComparer<T>)ComparerHelpers.CreateDefaultEqualityComparer(typeof(T));
public static EqualityComparer<T> Default { [Intrinsic] get; } = Create();
}

public sealed partial class GenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ private MethodIL TryGetPerInstantiationIntrinsicMethodIL(MethodDesc method)
return InterlockedIntrinsics.EmitIL(_compilationModuleGroup, method);
}

if (mdType.Namespace.SequenceEqual("System.Collections.Generic"u8))
{
if (mdType.Name.SequenceEqual("Comparer`1"u8))
{
if (method.Name.SequenceEqual("Create"u8))
return ComparerIntrinsics.EmitComparerCreate(method);
}
else if (mdType.Name.SequenceEqual("EqualityComparer`1"u8))
{
if (method.Name.SequenceEqual("Create"u8))
return ComparerIntrinsics.EmitEqualityComparerCreate(method);
}
}
Comment thread
BrzVlad marked this conversation as resolved.

return null;
}

Expand Down
Loading