diff --git a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs index c0ae5b16fe726..02c57d247eaa8 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -428,7 +428,6 @@ public sealed override Delegate[] GetInvocationList() 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) { @@ -436,14 +435,12 @@ public sealed override Delegate[] GetInvocationList() // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? true : false; + return d1 is null; } 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) { @@ -453,8 +450,7 @@ public sealed override Delegate[] GetInvocationList() // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? false : true; + return d1 is not null; } return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs index b05af345fe296..e70515b0d53da 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/MulticastDelegate.cs @@ -5,8 +5,8 @@ using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime; -using System.Runtime.Serialization; using System.Runtime.CompilerServices; +using System.Runtime.Serialization; using Internal.Runtime.CompilerServices; @@ -109,7 +109,6 @@ public override sealed int 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 ==(MulticastDelegate? d1, MulticastDelegate? d2) { @@ -117,14 +116,12 @@ public override sealed int GetHashCode() // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? true : false; + return d1 is null; } 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) { @@ -134,8 +131,7 @@ public override sealed int GetHashCode() // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? false : true; + return d1 is not null; } return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1); diff --git a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs index 360b851d66271..6975ab74bc914 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs @@ -556,45 +556,44 @@ private static void InsertionSort(Span keys) // - The floating-point comparisons here assume no NaNs, which is valid only because the sorting routines // themselves special-case NaN with a pre-pass that ensures none are present in the values being sorted // by moving them all to the front first and then sorting the rest. - // - The `? true : false` is to work-around poor codegen: https://github.com/dotnet/runtime/issues/37904#issuecomment-644180265. // - These are duplicated here rather than being on a helper type due to current limitations around generic inlining. [MethodImpl(MethodImplOptions.AggressiveInlining)] // compiles to a single comparison or method call private static bool LessThan(ref T left, ref T right) { - if (typeof(T) == typeof(byte)) return (byte)(object)left < (byte)(object)right ? true : false; - if (typeof(T) == typeof(sbyte)) return (sbyte)(object)left < (sbyte)(object)right ? true : false; - if (typeof(T) == typeof(ushort)) return (ushort)(object)left < (ushort)(object)right ? true : false; - if (typeof(T) == typeof(short)) return (short)(object)left < (short)(object)right ? true : false; - if (typeof(T) == typeof(uint)) return (uint)(object)left < (uint)(object)right ? true : false; - if (typeof(T) == typeof(int)) return (int)(object)left < (int)(object)right ? true : false; - if (typeof(T) == typeof(ulong)) return (ulong)(object)left < (ulong)(object)right ? true : false; - if (typeof(T) == typeof(long)) return (long)(object)left < (long)(object)right ? true : false; - if (typeof(T) == typeof(nuint)) return (nuint)(object)left < (nuint)(object)right ? true : false; - if (typeof(T) == typeof(nint)) return (nint)(object)left < (nint)(object)right ? true : false; - if (typeof(T) == typeof(float)) return (float)(object)left < (float)(object)right ? true : false; - if (typeof(T) == typeof(double)) return (double)(object)left < (double)(object)right ? true : false; - if (typeof(T) == typeof(Half)) return (Half)(object)left < (Half)(object)right ? true : false; - return left.CompareTo(right) < 0 ? true : false; + if (typeof(T) == typeof(byte)) return (byte)(object)left < (byte)(object)right; + if (typeof(T) == typeof(sbyte)) return (sbyte)(object)left < (sbyte)(object)right; + if (typeof(T) == typeof(ushort)) return (ushort)(object)left < (ushort)(object)right; + if (typeof(T) == typeof(short)) return (short)(object)left < (short)(object)right; + if (typeof(T) == typeof(uint)) return (uint)(object)left < (uint)(object)right; + if (typeof(T) == typeof(int)) return (int)(object)left < (int)(object)right; + if (typeof(T) == typeof(ulong)) return (ulong)(object)left < (ulong)(object)right; + if (typeof(T) == typeof(long)) return (long)(object)left < (long)(object)right; + if (typeof(T) == typeof(nuint)) return (nuint)(object)left < (nuint)(object)right; + if (typeof(T) == typeof(nint)) return (nint)(object)left < (nint)(object)right; + if (typeof(T) == typeof(float)) return (float)(object)left < (float)(object)right; + if (typeof(T) == typeof(double)) return (double)(object)left < (double)(object)right; + if (typeof(T) == typeof(Half)) return (Half)(object)left < (Half)(object)right; + return left.CompareTo(right) < 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] // compiles to a single comparison or method call private static bool GreaterThan(ref T left, ref T right) { - if (typeof(T) == typeof(byte)) return (byte)(object)left > (byte)(object)right ? true : false; - if (typeof(T) == typeof(sbyte)) return (sbyte)(object)left > (sbyte)(object)right ? true : false; - if (typeof(T) == typeof(ushort)) return (ushort)(object)left > (ushort)(object)right ? true : false; - if (typeof(T) == typeof(short)) return (short)(object)left > (short)(object)right ? true : false; - if (typeof(T) == typeof(uint)) return (uint)(object)left > (uint)(object)right ? true : false; - if (typeof(T) == typeof(int)) return (int)(object)left > (int)(object)right ? true : false; - if (typeof(T) == typeof(ulong)) return (ulong)(object)left > (ulong)(object)right ? true : false; - if (typeof(T) == typeof(long)) return (long)(object)left > (long)(object)right ? true : false; - if (typeof(T) == typeof(nuint)) return (nuint)(object)left > (nuint)(object)right ? true : false; - if (typeof(T) == typeof(nint)) return (nint)(object)left > (nint)(object)right ? true : false; - if (typeof(T) == typeof(float)) return (float)(object)left > (float)(object)right ? true : false; - if (typeof(T) == typeof(double)) return (double)(object)left > (double)(object)right ? true : false; - if (typeof(T) == typeof(Half)) return (Half)(object)left > (Half)(object)right ? true : false; - return left.CompareTo(right) > 0 ? true : false; + if (typeof(T) == typeof(byte)) return (byte)(object)left > (byte)(object)right; + if (typeof(T) == typeof(sbyte)) return (sbyte)(object)left > (sbyte)(object)right; + if (typeof(T) == typeof(ushort)) return (ushort)(object)left > (ushort)(object)right; + if (typeof(T) == typeof(short)) return (short)(object)left > (short)(object)right; + if (typeof(T) == typeof(uint)) return (uint)(object)left > (uint)(object)right; + if (typeof(T) == typeof(int)) return (int)(object)left > (int)(object)right; + if (typeof(T) == typeof(ulong)) return (ulong)(object)left > (ulong)(object)right; + if (typeof(T) == typeof(long)) return (long)(object)left > (long)(object)right; + if (typeof(T) == typeof(nuint)) return (nuint)(object)left > (nuint)(object)right; + if (typeof(T) == typeof(nint)) return (nint)(object)left > (nint)(object)right; + if (typeof(T) == typeof(float)) return (float)(object)left > (float)(object)right; + if (typeof(T) == typeof(double)) return (double)(object)left > (double)(object)right; + if (typeof(T) == typeof(Half)) return (Half)(object)left > (Half)(object)right; + return left.CompareTo(right) > 0; } } @@ -1054,44 +1053,43 @@ private static void InsertionSort(Span keys, Span values) // - The floating-point comparisons here assume no NaNs, which is valid only because the sorting routines // themselves special-case NaN with a pre-pass that ensures none are present in the values being sorted // by moving them all to the front first and then sorting the rest. - // - The `? true : false` is to work-around poor codegen: https://github.com/dotnet/runtime/issues/37904#issuecomment-644180265. // - These are duplicated here rather than being on a helper type due to current limitations around generic inlining. [MethodImpl(MethodImplOptions.AggressiveInlining)] // compiles to a single comparison or method call private static bool LessThan(ref TKey left, ref TKey right) { - if (typeof(TKey) == typeof(byte)) return (byte)(object)left < (byte)(object)right ? true : false; - if (typeof(TKey) == typeof(sbyte)) return (sbyte)(object)left < (sbyte)(object)right ? true : false; - if (typeof(TKey) == typeof(ushort)) return (ushort)(object)left < (ushort)(object)right ? true : false; - if (typeof(TKey) == typeof(short)) return (short)(object)left < (short)(object)right ? true : false; - if (typeof(TKey) == typeof(uint)) return (uint)(object)left < (uint)(object)right ? true : false; - if (typeof(TKey) == typeof(int)) return (int)(object)left < (int)(object)right ? true : false; - if (typeof(TKey) == typeof(ulong)) return (ulong)(object)left < (ulong)(object)right ? true : false; - if (typeof(TKey) == typeof(long)) return (long)(object)left < (long)(object)right ? true : false; - if (typeof(TKey) == typeof(nuint)) return (nuint)(object)left < (nuint)(object)right ? true : false; - if (typeof(TKey) == typeof(nint)) return (nint)(object)left < (nint)(object)right ? true : false; - if (typeof(TKey) == typeof(float)) return (float)(object)left < (float)(object)right ? true : false; - if (typeof(TKey) == typeof(double)) return (double)(object)left < (double)(object)right ? true : false; - if (typeof(TKey) == typeof(Half)) return (Half)(object)left < (Half)(object)right ? true : false; + if (typeof(TKey) == typeof(byte)) return (byte)(object)left < (byte)(object)right; + if (typeof(TKey) == typeof(sbyte)) return (sbyte)(object)left < (sbyte)(object)right; + if (typeof(TKey) == typeof(ushort)) return (ushort)(object)left < (ushort)(object)right; + if (typeof(TKey) == typeof(short)) return (short)(object)left < (short)(object)right; + if (typeof(TKey) == typeof(uint)) return (uint)(object)left < (uint)(object)right; + if (typeof(TKey) == typeof(int)) return (int)(object)left < (int)(object)right; + if (typeof(TKey) == typeof(ulong)) return (ulong)(object)left < (ulong)(object)right; + if (typeof(TKey) == typeof(long)) return (long)(object)left < (long)(object)right; + if (typeof(TKey) == typeof(nuint)) return (nuint)(object)left < (nuint)(object)right; + if (typeof(TKey) == typeof(nint)) return (nint)(object)left < (nint)(object)right; + if (typeof(TKey) == typeof(float)) return (float)(object)left < (float)(object)right; + if (typeof(TKey) == typeof(double)) return (double)(object)left < (double)(object)right; + if (typeof(TKey) == typeof(Half)) return (Half)(object)left < (Half)(object)right; return left.CompareTo(right) < 0 ? true : false; } [MethodImpl(MethodImplOptions.AggressiveInlining)] // compiles to a single comparison or method call private static bool GreaterThan(ref TKey left, ref TKey right) { - if (typeof(TKey) == typeof(byte)) return (byte)(object)left > (byte)(object)right ? true : false; - if (typeof(TKey) == typeof(sbyte)) return (sbyte)(object)left > (sbyte)(object)right ? true : false; - if (typeof(TKey) == typeof(ushort)) return (ushort)(object)left > (ushort)(object)right ? true : false; - if (typeof(TKey) == typeof(short)) return (short)(object)left > (short)(object)right ? true : false; - if (typeof(TKey) == typeof(uint)) return (uint)(object)left > (uint)(object)right ? true : false; - if (typeof(TKey) == typeof(int)) return (int)(object)left > (int)(object)right ? true : false; - if (typeof(TKey) == typeof(ulong)) return (ulong)(object)left > (ulong)(object)right ? true : false; - if (typeof(TKey) == typeof(long)) return (long)(object)left > (long)(object)right ? true : false; - if (typeof(TKey) == typeof(nuint)) return (nuint)(object)left > (nuint)(object)right ? true : false; - if (typeof(TKey) == typeof(nint)) return (nint)(object)left > (nint)(object)right ? true : false; - if (typeof(TKey) == typeof(float)) return (float)(object)left > (float)(object)right ? true : false; - if (typeof(TKey) == typeof(double)) return (double)(object)left > (double)(object)right ? true : false; - if (typeof(TKey) == typeof(Half)) return (Half)(object)left > (Half)(object)right ? true : false; + if (typeof(TKey) == typeof(byte)) return (byte)(object)left > (byte)(object)right; + if (typeof(TKey) == typeof(sbyte)) return (sbyte)(object)left > (sbyte)(object)right; + if (typeof(TKey) == typeof(ushort)) return (ushort)(object)left > (ushort)(object)right; + if (typeof(TKey) == typeof(short)) return (short)(object)left > (short)(object)right; + if (typeof(TKey) == typeof(uint)) return (uint)(object)left > (uint)(object)right; + if (typeof(TKey) == typeof(int)) return (int)(object)left > (int)(object)right; + if (typeof(TKey) == typeof(ulong)) return (ulong)(object)left > (ulong)(object)right; + if (typeof(TKey) == typeof(long)) return (long)(object)left > (long)(object)right; + if (typeof(TKey) == typeof(nuint)) return (nuint)(object)left > (nuint)(object)right; + if (typeof(TKey) == typeof(nint)) return (nint)(object)left > (nint)(object)right; + if (typeof(TKey) == typeof(float)) return (float)(object)left > (float)(object)right; + if (typeof(TKey) == typeof(double)) return (double)(object)left > (double)(object)right; + if (typeof(TKey) == typeof(Half)) return (Half)(object)left > (Half)(object)right; return left.CompareTo(right) > 0 ? true : false; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs index 03ed33ceb1d5b..448776296bbf3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/DateTime.cs +++ b/src/libraries/System.Private.CoreLib/src/System/DateTime.cs @@ -1085,8 +1085,7 @@ public static bool IsLeapYear(int year) } if ((year & 3) != 0) return false; if ((year & 15) == 0) return true; - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (uint)year % 25 != 0 ? true : false; + return (uint)year % 25 != 0; } // Constructs a DateTime from a string. The string must specify a diff --git a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs index 9f22b48fde707..b9cb7624fc6d2 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs @@ -93,7 +93,6 @@ public abstract partial class Delegate : ICloneable, ISerializable return newDelegate; } - // 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) { @@ -101,14 +100,12 @@ public abstract partial class Delegate : ICloneable, ISerializable // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? true : false; + return d1 is null; } 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 !=(Delegate? d1, Delegate? d2) { @@ -116,8 +113,7 @@ public abstract partial class Delegate : ICloneable, ISerializable // so it can become a simple test if (d2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (d1 is null) ? false : true; + return d1 is not null; } return ReferenceEquals(d2, d1) ? false : !d2.Equals(d1); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs index 60e6f3647c2cc..262431def7455 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs @@ -164,9 +164,7 @@ internal static bool EqualsIgnoreCase(ref char charA, ref char charB, int length return false; // not exact match, and first input isn't in [A-Za-z] } - // The ternary operator below seems redundant but helps RyuJIT generate more optimal code. - // See https://github.com/dotnet/runtime/issues/4207. - return (valueA == (valueB | 0x20u)) ? true : false; + return valueA == (valueB | 0x20u); } Debug.Assert(length == 0); 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 93ca171b29e31..4b2cbae329bec 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/SortVersion.cs @@ -7,7 +7,7 @@ namespace System.Globalization { [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class SortVersion : IEquatable { private readonly int m_NlsVersion; // Do not rename (binary serialization) @@ -59,7 +59,6 @@ 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) { @@ -67,8 +66,7 @@ public override int GetHashCode() // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } return right.Equals(left); diff --git a/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs b/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs index d9c0662e81d25..c01bc5ab10ecb 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Number.Parsing.cs @@ -2068,8 +2068,7 @@ private static bool TrailingZeros(ReadOnlySpan value, int index) return null; } - // Ternary op is a workaround for https://github.com/dotnet/runtime/issues/4207 - private static bool IsWhite(int ch) => ch == 0x20 || (uint)(ch - 0x09) <= (0x0D - 0x09) ? true : false; + private static bool IsWhite(int ch) => ch == 0x20 || (uint)(ch - 0x09) <= (0x0D - 0x09); private static bool IsDigit(int ch) => ((uint)ch - '0') <= 9; 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 a5b088b878cfe..59bb4d1a8862e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs @@ -8,8 +8,8 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.Serialization; using System.Security; -using System.Runtime.CompilerServices; using System.Runtime.Loader; +using System.Runtime.CompilerServices; namespace System.Reflection { @@ -186,12 +186,11 @@ public override string ToString() // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 178c872b34b1d..c4619fdead121 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/ConstructorInfo.cs @@ -28,12 +28,11 @@ protected ConstructorInfo() { } // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 02f19f16bbbd5..07e1f5bd15c07 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/EventInfo.cs @@ -91,12 +91,11 @@ public virtual void RemoveEventHandler(object? target, Delegate? handler) // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 a50821d7ed02b..a2090f56d483a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/FieldInfo.cs @@ -46,12 +46,11 @@ protected FieldInfo() { } // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 61381b7edc8f2..89cc304a0ef42 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MemberInfo.cs @@ -50,12 +50,11 @@ public virtual Module Module // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 f1267bb778170..d8b78883150b7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBase.cs @@ -70,12 +70,11 @@ this is ConstructorInfo && // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 7e16e554c0807..5e8afa6d70e30 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodInfo.cs @@ -45,12 +45,11 @@ protected MethodInfo() { } // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 cbf100581b003..5ff7b76335d80 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Module.cs @@ -144,12 +144,11 @@ public virtual Type[] FindTypes(TypeFilter? filter, object? filterCriteria) // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } 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 1208a88b6b3d8..89f398f1f9172 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/PropertyInfo.cs @@ -65,12 +65,11 @@ protected PropertyInfo() { } // so it can become a simple test if (right is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (left is null) ? true : false; + return left is null; } // Try fast reference equality and opposite null check prior to calling the slower virtual Equals - if ((object?)left == (object)right) + if (ReferenceEquals(left, right)) { return true; } diff --git a/src/libraries/System.Private.CoreLib/src/System/String.cs b/src/libraries/System.Private.CoreLib/src/System/String.cs index 2183d5e59befe..37ad18ad93a93 100644 --- a/src/libraries/System.Private.CoreLib/src/System/String.cs +++ b/src/libraries/System.Private.CoreLib/src/System/String.cs @@ -476,9 +476,7 @@ public char[] ToCharArray(int startIndex, int length) [NonVersionable] public static bool IsNullOrEmpty([NotNullWhen(false)] string? value) { - // Ternary operator returning true/false prevents redundant asm generation: - // https://github.com/dotnet/runtime/issues/4207 - return (value == null || 0 == value.Length) ? true : false; + return value == null || value.Length == 0; } public static bool IsNullOrWhiteSpace([NotNullWhen(false)] string? value) diff --git a/src/libraries/System.Private.CoreLib/src/System/Version.cs b/src/libraries/System.Private.CoreLib/src/System/Version.cs index 96da170cc6dd7..431c0a1e81cd3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Version.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Version.cs @@ -1,11 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Globalization; using System.Diagnostics; -using System.Text; -using System.Runtime.CompilerServices; using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Runtime.CompilerServices; namespace System { @@ -16,7 +15,7 @@ namespace System // specified component. [Serializable] - [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] + [TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] public sealed class Version : ICloneable, IComparable, IComparable, IEquatable, ISpanFormattable { // AssemblyName depends on the order staying the same @@ -370,7 +369,6 @@ private static bool TryParseComponent(ReadOnlySpan component, string compo 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) { @@ -378,8 +376,7 @@ private static bool TryParseComponent(ReadOnlySpan component, string compo // so it can become a simple test if (v2 is null) { - // return true/false not the test result https://github.com/dotnet/runtime/issues/4207 - return (v1 is null) ? true : false; + return v1 is null; } // Quick reference equality test prior to calling the virtual Equality