From 177ad74077b24ab4d372523f644ee7d33694571b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= Date: Fri, 9 Feb 2024 00:45:11 +0100 Subject: [PATCH 1/2] Optimize equality operators --- .../System.Private.CoreLib/src/System/Delegate.cs | 14 ++++++-------- .../src/System/Globalization/SortVersion.cs | 6 +++--- .../src/System/MulticastDelegate.cs | 14 ++++++-------- .../src/System/Reflection/Assembly.cs | 10 +--------- .../src/System/Reflection/ConstructorInfo.cs | 10 +--------- .../src/System/Reflection/EventInfo.cs | 10 +--------- .../src/System/Reflection/FieldInfo.cs | 10 +--------- .../src/System/Reflection/MemberInfo.cs | 10 +--------- .../src/System/Reflection/MethodBase.cs | 10 +--------- .../src/System/Reflection/MethodInfo.cs | 10 +--------- .../src/System/Reflection/Module.cs | 10 +--------- .../src/System/Reflection/PropertyInfo.cs | 10 +--------- .../src/System/Runtime/Versioning/FrameworkName.cs | 6 +++--- .../System.Private.CoreLib/src/System/Type.cs | 5 +++-- .../System.Private.CoreLib/src/System/Version.cs | 9 +++------ 15 files changed, 33 insertions(+), 111 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs index d24059770d5f88..403d6eac3ae9d3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs @@ -164,14 +164,12 @@ public bool MoveNext() [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Delegate? d1, Delegate? 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) + if (ReferenceEquals(d1, d2)) { - return d1 is null; + return true; } - return ReferenceEquals(d2, d1) ? true : d2.Equals((object?)d1); + return d2 is not null && d2.Equals(d1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -179,12 +177,12 @@ public bool MoveNext() { // 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) + if (ReferenceEquals(d1, d2)) { - return d1 is not null; + return false; } - return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1); + return d2 is not null && !d2.Equals(d1); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs index 448a0d1c387354..95f87a8d587b04 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs @@ -64,12 +64,12 @@ public override int GetHashCode() { // Test "right" first to allow branch elimination when inlined for null checks (== null) // so it can become a simple test - if (right is null) + if (ReferenceEquals(left, right)) { - return left is null; + return true; } - return right.Equals(left); + return right is not null && right.Equals(left); } public static bool operator !=(SortVersion? left, SortVersion? right) => diff --git a/src/libraries/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/libraries/System.Private.CoreLib/src/System/MulticastDelegate.cs index 2508f2dc09f15a..b1b2962b4502fd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -28,14 +28,12 @@ protected MulticastDelegate([DynamicallyAccessedMembers(DynamicallyAccessedMembe [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(MulticastDelegate? d1, MulticastDelegate? 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) + if (ReferenceEquals(d1, d2)) { - return d1 is null; + return true; } - return ReferenceEquals(d2, d1) ? true : d2.Equals((object?)d1); + return d2 is not null && d2.Equals(d1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -45,12 +43,12 @@ protected MulticastDelegate([DynamicallyAccessedMembers(DynamicallyAccessedMembe // 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) + if (ReferenceEquals(d1, d2)) { - return d1 is not null; + return false; } - return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1); + return d2 is not null && !d2.Equals(d1); } } #pragma warning restore CS0660, CS0661 diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs index d467fd6fb08242..b3677e8e6ebc06 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -187,20 +187,12 @@ public override string ToString() [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Assembly? left, Assembly? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(Assembly? left, Assembly? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs index c4619fdead1218..ad0688eb12c878 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs @@ -24,20 +24,12 @@ protected ConstructorInfo() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(ConstructorInfo? left, ConstructorInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(ConstructorInfo? left, ConstructorInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs index a42feec69e5d5c..5aee3cff18e73e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs @@ -87,20 +87,12 @@ public virtual void RemoveEventHandler(object? target, Delegate? handler) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(EventInfo? left, EventInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(EventInfo? left, EventInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs index 374c0ba5aeeb13..3d3e0057e6529a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs @@ -43,20 +43,12 @@ protected FieldInfo() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(FieldInfo? left, FieldInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(FieldInfo? left, FieldInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs index 89cc304a0ef42d..8c986448bef15b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs @@ -46,20 +46,12 @@ public virtual Module Module [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(MemberInfo? left, MemberInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(MemberInfo? left, MemberInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs index 087f9953a3af4d..a35029cba3810e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -68,20 +68,12 @@ this is ConstructorInfo && [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(MethodBase? left, MethodBase? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(MethodBase? left, MethodBase? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs index 5e8afa6d70e30d..994eedbe3d4053 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs @@ -41,20 +41,12 @@ protected MethodInfo() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(MethodInfo? left, MethodInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(MethodInfo? left, MethodInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs index ed57d6891e283c..a4de993fc9bbd8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs @@ -148,20 +148,12 @@ public virtual Type[] FindTypes(TypeFilter? filter, object? filterCriteria) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Module? left, Module? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(Module? left, Module? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs index 24c1196334a8b0..abb1f1dc6a4fe2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs @@ -62,20 +62,12 @@ protected PropertyInfo() { } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(PropertyInfo? left, PropertyInfo? 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 left is null; - } - - // Try fast reference equality and opposite null check prior to calling the slower virtual Equals if (ReferenceEquals(left, right)) { return true; } - return (left is null) ? false : left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(PropertyInfo? left, PropertyInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs index 973a13aafabf2a..7156132e31faa8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs @@ -197,12 +197,12 @@ public FrameworkName(string frameworkName) public static bool operator ==(FrameworkName? left, FrameworkName? right) { - if (left is null) + if (ReferenceEquals(left, right)) { - return right is null; + return true; } - return left.Equals(right); + return right is not null && right.Equals(left); } public static bool operator !=(FrameworkName? left, FrameworkName? right) diff --git a/src/libraries/System.Private.CoreLib/src/System/Type.cs b/src/libraries/System.Private.CoreLib/src/System/Type.cs index 17e4636296c177..e30fe8086bdb01 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Type.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Type.cs @@ -663,7 +663,6 @@ internal string FormatTypeName() public override string ToString() => "Type: " + Name; // Why do we add the "Type: " prefix? - public override bool Equals(object? o) => o == null ? false : Equals(o as Type); public override int GetHashCode() { Type systemType = UnderlyingSystemType; @@ -671,7 +670,9 @@ public override int GetHashCode() return systemType.GetHashCode(); return base.GetHashCode(); } - public virtual bool Equals(Type? o) => o == null ? false : ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType); + + public override bool Equals(object? o) => o is Type type && Equals(type); + public virtual bool Equals(Type? o) => o is not null && ReferenceEquals(this.UnderlyingSystemType, o.UnderlyingSystemType); [Intrinsic] public static bool operator ==(Type? left, Type? right) diff --git a/src/libraries/System.Private.CoreLib/src/System/Version.cs b/src/libraries/System.Private.CoreLib/src/System/Version.cs index 99c26d59a91439..4a9f73c55b6a53 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Version.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Version.cs @@ -390,15 +390,12 @@ private static bool TryParseComponent(ReadOnlySpan component, string compo [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool operator ==(Version? v1, Version? v2) { - // Test "right" first to allow branch elimination when inlined for null checks (== null) - // so it can become a simple test - if (v2 is null) + if (ReferenceEquals(v1, v2)) { - return v1 is null; + return true; } - // Quick reference equality test prior to calling the virtual Equality - return ReferenceEquals(v2, v1) ? true : v2.Equals(v1); + return v2 is not null && v2.Equals(v1); } public static bool operator !=(Version? v1, Version? v2) => !(v1 == v2); From 7098969aaa0c15916bf4a2949da7819caea945d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Petryka?= Date: Sat, 10 Feb 2024 17:38:03 +0100 Subject: [PATCH 2/2] Swap elements back --- .../System.Private.CoreLib/src/System/Reflection/Assembly.cs | 2 +- .../src/System/Reflection/ConstructorInfo.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/EventInfo.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/FieldInfo.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/MemberInfo.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/MethodBase.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/MethodInfo.cs | 2 +- .../System.Private.CoreLib/src/System/Reflection/Module.cs | 2 +- .../src/System/Reflection/PropertyInfo.cs | 2 +- .../src/System/Runtime/Versioning/FrameworkName.cs | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs index b3677e8e6ebc06..20b07e73dbc738 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -192,7 +192,7 @@ public override string ToString() return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(Assembly? left, Assembly? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs index ad0688eb12c878..d54dbd6d103bf2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs @@ -29,7 +29,7 @@ protected ConstructorInfo() { } return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(ConstructorInfo? left, ConstructorInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs index 5aee3cff18e73e..c0fe1fad5aadde 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs @@ -92,7 +92,7 @@ public virtual void RemoveEventHandler(object? target, Delegate? handler) return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(EventInfo? left, EventInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs index 3d3e0057e6529a..bbf3cbac69f785 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs @@ -48,7 +48,7 @@ protected FieldInfo() { } return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(FieldInfo? left, FieldInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs index 8c986448bef15b..186559e47f7d3c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs @@ -51,7 +51,7 @@ public virtual Module Module return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(MemberInfo? left, MemberInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs index a35029cba3810e..8d476aaa2d4458 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -73,7 +73,7 @@ this is ConstructorInfo && return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(MethodBase? left, MethodBase? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs index 994eedbe3d4053..0c8a39a5817dcd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs @@ -46,7 +46,7 @@ protected MethodInfo() { } return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(MethodInfo? left, MethodInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs index a4de993fc9bbd8..58773e55314f0a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs @@ -153,7 +153,7 @@ public virtual Type[] FindTypes(TypeFilter? filter, object? filterCriteria) return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(Module? left, Module? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs index abb1f1dc6a4fe2..c54a1ec27003ac 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs @@ -67,7 +67,7 @@ protected PropertyInfo() { } return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(PropertyInfo? left, PropertyInfo? right) => !(left == right); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs index 7156132e31faa8..9612f33b55eab0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Versioning/FrameworkName.cs @@ -202,7 +202,7 @@ public FrameworkName(string frameworkName) return true; } - return right is not null && right.Equals(left); + return left is not null && left.Equals(right); } public static bool operator !=(FrameworkName? left, FrameworkName? right)