Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Maintain left.Equals(right) order for equality for compat #21829

Merged
merged 1 commit into from
Jan 6, 2019
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
10 changes: 7 additions & 3 deletions src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public override string ToString()
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)
{
Expand All @@ -160,8 +159,13 @@ public override string ToString()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ protected ConstructorInfo() { }
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)]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benaadams Did you intend to delete only the comment, not the associated attribute?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as I think its inaccurrate now (saying its actually a very small method that's just misunderstood by the Jit)

public static bool operator ==(ConstructorInfo left, ConstructorInfo right)
{
Expand All @@ -34,8 +33,13 @@ protected ConstructorInfo() { }
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);
Expand Down
10 changes: 7 additions & 3 deletions src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ public virtual void RemoveEventHandler(object target, Delegate handler)
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)
{
Expand All @@ -112,8 +111,13 @@ public virtual void RemoveEventHandler(object target, Delegate handler)
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);
Expand Down
10 changes: 7 additions & 3 deletions src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ protected FieldInfo() { }
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)
{
Expand All @@ -52,8 +51,13 @@ protected FieldInfo() { }
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public virtual Module Module
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)
{
Expand All @@ -57,8 +56,13 @@ public virtual Module Module
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public bool IsConstructor
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)
{
Expand All @@ -75,8 +74,13 @@ public bool IsConstructor
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ protected MethodInfo() { }
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)
{
Expand All @@ -41,8 +40,13 @@ protected MethodInfo() { }
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);
Expand Down
10 changes: 7 additions & 3 deletions src/System.Private.CoreLib/shared/System/Reflection/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria)
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)
{
Expand All @@ -128,8 +127,13 @@ public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria)
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ protected PropertyInfo() { }
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)
{
Expand All @@ -71,8 +70,13 @@ protected PropertyInfo() { }
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);
Expand Down