summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Adams <thundercat@illyriad.co.uk>2019-01-06 05:24:35 +0100
committerJan Kotas <jkotas@microsoft.com>2019-01-05 20:24:35 -0800
commitdda6df6ceaf0785c7bfd52fce3084b7f157c9588 (patch)
treed4c6b127e0dd523beb6e73f0581b400dd0934999 /src
parentda2fe0efcb1f022087108abb9c6000561aee8751 (diff)
downloadcoreclr-dda6df6ceaf0785c7bfd52fce3084b7f157c9588.tar.gz
coreclr-dda6df6ceaf0785c7bfd52fce3084b7f157c9588.tar.bz2
coreclr-dda6df6ceaf0785c7bfd52fce3084b7f157c9588.zip
Maintain left.Equals(right) order for equality for compat (#21829)
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/Module.cs10
-rw-r--r--src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs10
9 files changed, 63 insertions, 27 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
index c7b39ff8df..bc8b4cdaf9 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
@@ -148,7 +148,6 @@ 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)
{
@@ -160,8 +159,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(Assembly left, Assembly right)
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs
index 3d8750cbba..1e31194cfc 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/ConstructorInfo.cs
@@ -22,7 +22,6 @@ 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)
{
@@ -34,8 +33,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(ConstructorInfo left, ConstructorInfo right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
index e35261339c..fa7e49df24 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
@@ -100,7 +100,6 @@ 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 ==(EventInfo left, EventInfo right)
{
@@ -112,8 +111,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(EventInfo left, EventInfo right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
index 53bcf17c2c..fd577b668d 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
@@ -40,7 +40,6 @@ 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)
{
@@ -52,8 +51,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(FieldInfo left, FieldInfo right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
index 2f439d8c8c..8d15005fb4 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
@@ -45,7 +45,6 @@ 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)
{
@@ -57,8 +56,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(MemberInfo left, MemberInfo right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
index e5ca0d5de1..914689c5ba 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
@@ -63,7 +63,6 @@ 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)
{
@@ -75,8 +74,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(MethodBase left, MethodBase right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
index 920a9a2da8..5552854341 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
@@ -29,7 +29,6 @@ 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 ==(MethodInfo left, MethodInfo right)
{
@@ -41,8 +40,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(MethodInfo left, MethodInfo right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/Module.cs b/src/System.Private.CoreLib/shared/System/Reflection/Module.cs
index 5d2e418f06..934ea75899 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/Module.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/Module.cs
@@ -116,7 +116,6 @@ 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)
{
@@ -128,8 +127,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(Module left, Module right) => !(left == right);
diff --git a/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs
index 562907f485..7fbb7eed44 100644
--- a/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs
+++ b/src/System.Private.CoreLib/shared/System/Reflection/PropertyInfo.cs
@@ -59,7 +59,6 @@ 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)
{
@@ -71,8 +70,13 @@ namespace System.Reflection
return (left is null) ? true : false;
}
- // Quick reference equality test prior to calling the virtual Equality
- return ReferenceEquals(right, left) ? true : right.Equals(left);
+ // Try fast reference equality and opposite null check prior to calling the slower virtual Equals
+ if ((object)left == (object)right)
+ {
+ return true;
+ }
+
+ return (left is null) ? false : left.Equals(right);
}
public static bool operator !=(PropertyInfo left, PropertyInfo right) => !(left == right);