diff options
-rw-r--r-- | src/jit/importer.cpp | 10 | ||||
-rw-r--r-- | src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs | 15 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/jit/importer.cpp b/src/jit/importer.cpp index 7f8f49e055..9c02159850 100644 --- a/src/jit/importer.cpp +++ b/src/jit/importer.cpp @@ -19443,11 +19443,17 @@ CORINFO_CLASS_HANDLE Compiler::impGetSpecialIntrinsicExactReturnType(CORINFO_MET assert(sig.sigInst.classInstCount == 1); CORINFO_CLASS_HANDLE typeHnd = sig.sigInst.classInst[0]; assert(typeHnd != nullptr); + + // Lookup can incorrect when we have __Canon as it won't appear + // to implement any interface types. + // + // And if we do not have a final type, devirt & inlining is + // unlikely to result in much simplification. + // + // We can use CORINFO_FLG_FINAL to screen out both of these cases. const DWORD typeAttribs = info.compCompHnd->getClassAttribs(typeHnd); const bool isFinalType = ((typeAttribs & CORINFO_FLG_FINAL) != 0); - // If we do not have a final type, devirt & inlining is - // unlikely to result in much simplification. if (isFinalType) { result = info.compCompHnd->getDefaultEqualityComparerClass(typeHnd); diff --git a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs index 06af626526..3af0cf4da1 100644 --- a/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs +++ b/src/mscorlib/src/System/Collections/Generic/EqualityComparer.cs @@ -68,7 +68,7 @@ namespace System.Collections.Generic // to Equal bind to IEquatable<T>.Equals(T) instead of Object.Equals(Object) [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - internal class GenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T> + internal sealed class GenericEqualityComparer<T> : EqualityComparer<T> where T : IEquatable<T> { [MethodImpl(MethodImplOptions.AggressiveInlining)] public override bool Equals(T x, T y) @@ -274,7 +274,7 @@ namespace System.Collections.Generic // randomized string hashing GenericEqualityComparer<string> [Serializable] [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - internal class NonRandomizedStringEqualityComparer : GenericEqualityComparer<string> + internal sealed class NonRandomizedStringEqualityComparer : EqualityComparer<string> { private static IEqualityComparer<string> s_nonRandomizedComparer; @@ -290,6 +290,17 @@ namespace System.Collections.Generic } } + public override bool Equals(string x, string y) + { + if (x != null) + { + if (y != null) return x.Equals(y); + return false; + } + if (y != null) return false; + return true; + } + public override int GetHashCode(string obj) { if (obj == null) return 0; |