// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.CompilerServices;
+
namespace System.Globalization
{
[Serializable]
return m_NlsVersion * 7 | m_SortId.GetHashCode();
}
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(SortVersion left, SortVersion right)
{
- if (((object)left) != null)
- {
- return left.Equals(right);
- }
-
- if (((object)right) != null)
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
{
- return right.Equals(left);
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
}
- // Both null.
- return true;
+ return right.Equals(left);
}
public static bool operator !=(SortVersion left, SortVersion right)
using System.Configuration.Assemblies;
using System.Runtime.Serialization;
using System.Security;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object o) => base.Equals(o);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Assembly left, Assembly right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
- return left.Equals(right);
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(Assembly left, Assembly right)
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(ConstructorInfo left, ConstructorInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- return left.Equals(right);
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
+
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(ConstructorInfo left, ConstructorInfo right) => !(left == right);
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
+using System.Runtime.CompilerServices;
#if FEATURE_COMINTEROP
using EventRegistrationToken = System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken;
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(EventInfo left, EventInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
- return left.Equals(right);
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(EventInfo left, EventInfo right) => !(left == right);
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(FieldInfo left, FieldInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- return left.Equals(right);
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
+
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(FieldInfo left, FieldInfo right) => !(left == right);
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(MemberInfo left, MemberInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- Type type1, type2;
- MethodBase method1, method2;
- FieldInfo field1, field2;
- EventInfo event1, event2;
- PropertyInfo property1, property2;
-
- if ((type1 = left as Type) != null && (type2 = right as Type) != null)
- return type1 == type2;
- else if ((method1 = left as MethodBase) != null && (method2 = right as MethodBase) != null)
- return method1 == method2;
- else if ((field1 = left as FieldInfo) != null && (field2 = right as FieldInfo) != null)
- return field1 == field2;
- else if ((event1 = left as EventInfo) != null && (event2 = right as EventInfo) != null)
- return event1 == event2;
- else if ((property1 = left as PropertyInfo) != null && (property2 = right as PropertyInfo) != null)
- return property1 == property2;
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
- return false;
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(MemberInfo left, MemberInfo right) => !(left == right);
using System.Globalization;
using System.Diagnostics;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(MethodBase left, MethodBase right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- MethodInfo method1, method2;
- ConstructorInfo constructor1, constructor2;
-
- if ((method1 = left as MethodInfo) != null && (method2 = right as MethodInfo) != null)
- return method1 == method2;
- else if ((constructor1 = left as ConstructorInfo) != null && (constructor2 = right as ConstructorInfo) != null)
- return constructor1 == constructor2;
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
- return false;
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(MethodBase left, MethodBase right) => !(left == right);
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Runtime.CompilerServices;
+
namespace System.Reflection
{
public abstract partial class MethodInfo : MethodBase
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(MethodInfo left, MethodInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- return left.Equals(right);
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
+
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(MethodInfo left, MethodInfo right) => !(left == right);
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace System.Reflection
public override bool Equals(object o) => base.Equals(o);
public override int GetHashCode() => base.GetHashCode();
-
+
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Module left, Module right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
- return left.Equals(right);
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(Module left, Module right) => !(left == right);
using System.Diagnostics;
using System.Globalization;
+using System.Runtime.CompilerServices;
namespace System.Reflection
{
public override bool Equals(object obj) => base.Equals(obj);
public override int GetHashCode() => base.GetHashCode();
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(PropertyInfo left, PropertyInfo right)
{
- if (object.ReferenceEquals(left, right))
- return true;
-
- if ((object)left == null || (object)right == null)
- return false;
-
- return left.Equals(right);
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (right is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (left is null) ? true : false;
+ }
+
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(right, left) ? true : right.Equals(left);
}
public static bool operator !=(PropertyInfo left, PropertyInfo right) => !(left == right);
using System.Globalization;
using System.Diagnostics;
using System.Text;
+using System.Runtime.CompilerServices;
namespace System
{
return int.TryParse(component, NumberStyles.Integer, CultureInfo.InvariantCulture, out parsedComponent) && parsedComponent >= 0;
}
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Version v1, Version v2)
{
- if (v1 is null)
+ // Test "right" first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (v2 is null)
{
- return v2 is null;
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (v1 is null) ? true : false;
}
- return v1.Equals(v2);
+ // Quick reference equality test prior to calling the virtual Equality
+ return ReferenceEquals(v2, v1) ? true : v2.Equals(v1);
}
public static bool operator !=(Version v1, Version v2)
return d;
}
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Delegate d1, Delegate d2)
{
- if ((object)d1 == null)
- return (object)d2 == null;
+ // Test d2 first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (d2 is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (d1 is null) ? true : false;
+ }
- return d1.Equals(d2);
+ return ReferenceEquals(d2, d1) ? true : d2.Equals((object)d1);
}
public static bool operator !=(Delegate d1, Delegate d2)
{
- if ((object)d1 == null)
- return (object)d2 != null;
+ // Test d2 first to allow branch elimination when inlined for not null checks (!= null)
+ // so it can become a simple test
+ if (d2 is null)
+ {
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (d1 is null) ? false : true;
+ }
- return !d1.Equals(d2);
+ return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1);
}
//
using System.Diagnostics;
using System.Reflection;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
return del;
}
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(MulticastDelegate d1, MulticastDelegate d2)
{
- if (ReferenceEquals(d1, d2))
+ // Test d2 first to allow branch elimination when inlined for null checks (== null)
+ // so it can become a simple test
+ if (d2 is null)
{
- return true;
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (d1 is null) ? true : false;
}
- return d1 is null ? false : d1.Equals(d2);
+ return ReferenceEquals(d2, d1) ? true : d2.Equals((object)d1);
}
+ // Force inline as the true/false ternary takes it above ALWAYS_INLINE size even though the asm ends up smaller
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(MulticastDelegate d1, MulticastDelegate d2)
{
- if (ReferenceEquals(d1, d2))
+ // Can't call the == operator as it will call object==
+
+ // Test d2 first to allow branch elimination when inlined for not null checks (!= null)
+ // so it can become a simple test
+ if (d2 is null)
{
- return false;
+ // return true/false not the test result https://github.com/dotnet/coreclr/issues/914
+ return (d1 is null) ? false : true;
}
- return d1 is null ? true : !d1.Equals(d2);
+ return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1);
}
public override sealed int GetHashCode()