Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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]
Expand Down Expand Up @@ -75,20 +77,19 @@ public override int GetHashCode()
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)
Expand Down
18 changes: 12 additions & 6 deletions src/System.Private.CoreLib/shared/System/Reflection/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Configuration.Assemblies;
using System.Runtime.Serialization;
using System.Security;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand Down Expand Up @@ -147,15 +148,20 @@ 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)
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand All @@ -21,15 +22,20 @@ 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)]
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);
Expand Down
18 changes: 12 additions & 6 deletions src/System.Private.CoreLib/shared/System/Reflection/EventInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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;
Expand Down Expand Up @@ -99,15 +100,20 @@ 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)
{
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);
Expand Down
20 changes: 13 additions & 7 deletions src/System.Private.CoreLib/shared/System/Reflection/FieldInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand Down Expand Up @@ -39,15 +40,20 @@ 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)
{
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);
Expand Down
35 changes: 12 additions & 23 deletions src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand Down Expand Up @@ -44,32 +45,20 @@ 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)
{
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);
Expand Down
26 changes: 12 additions & 14 deletions src/System.Private.CoreLib/shared/System/Reflection/MethodBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Globalization;
using System.Diagnostics;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand Down Expand Up @@ -62,23 +63,20 @@ 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)
{
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);
Expand Down
21 changes: 14 additions & 7 deletions src/System.Private.CoreLib/shared/System/Reflection/MethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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
Expand All @@ -27,15 +29,20 @@ 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)
{
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);
Expand Down
20 changes: 13 additions & 7 deletions src/System.Private.CoreLib/shared/System/Reflection/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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
Expand Down Expand Up @@ -114,16 +115,21 @@ 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)
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;

namespace System.Reflection
{
Expand Down Expand Up @@ -58,15 +59,20 @@ 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)
{
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);
Expand Down
Loading