From 996b0127a6eb2b9d6a2f6f408ea5a9c1eb46a06f Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Fri, 7 Jul 2023 10:56:08 -0400 Subject: [PATCH] Reduce size of non-inlined ArgumentOutOfRangeException throw helpers (#88508) Keeping the arguments of the delegated throw method the same order as the callee avoids unnecessary spilling. --- .../src/System/ArgumentOutOfRangeException.cs | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs b/src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs index 45ae63f..48c941f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ArgumentOutOfRangeException.cs @@ -96,39 +96,39 @@ namespace System public virtual object? ActualValue => _actualValue; [DoesNotReturn] - private static void ThrowZero(string? paramName, T value) => + private static void ThrowZero(T value, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonZero, paramName, value)); [DoesNotReturn] - private static void ThrowNegative(string? paramName, T value) => + private static void ThrowNegative(T value, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegative, paramName, value)); [DoesNotReturn] - private static void ThrowNegativeOrZero(string? paramName, T value) => + private static void ThrowNegativeOrZero(T value, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNonNegativeNonZero, paramName, value)); [DoesNotReturn] - private static void ThrowGreater(string? paramName, T value, T other) => + private static void ThrowGreater(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLessOrEqual, paramName, value, other)); [DoesNotReturn] - private static void ThrowGreaterEqual(string? paramName, T value, T other) => + private static void ThrowGreaterEqual(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeLess, paramName, value, other)); [DoesNotReturn] - private static void ThrowLess(string? paramName, T value, T other) => + private static void ThrowLess(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreaterOrEqual, paramName, value, other)); [DoesNotReturn] - private static void ThrowLessEqual(string? paramName, T value, T other) => + private static void ThrowLessEqual(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeGreater, paramName, value, other)); [DoesNotReturn] - private static void ThrowEqual(string? paramName, T value, T other) => + private static void ThrowEqual(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeNotEqual, paramName, (object?)value ?? "null", (object?)other ?? "null")); [DoesNotReturn] - private static void ThrowNotEqual(string? paramName, T value, T other) => + private static void ThrowNotEqual(T value, T other, string? paramName) => throw new ArgumentOutOfRangeException(paramName, value, SR.Format(SR.ArgumentOutOfRange_Generic_MustBeEqual, paramName, (object?)value ?? "null", (object?)other ?? "null")); /// Throws an if is zero. @@ -138,7 +138,7 @@ namespace System where T : INumberBase { if (T.IsZero(value)) - ThrowZero(paramName, value); + ThrowZero(value, paramName); } /// Throws an if is negative. @@ -148,7 +148,7 @@ namespace System where T : INumberBase { if (T.IsNegative(value)) - ThrowNegative(paramName, value); + ThrowNegative(value, paramName); } /// Throws an if is negative or zero. @@ -158,7 +158,7 @@ namespace System where T : INumberBase { if (T.IsNegative(value) || T.IsZero(value)) - ThrowNegativeOrZero(paramName, value); + ThrowNegativeOrZero(value, paramName); } /// Throws an if is equal to . @@ -168,7 +168,7 @@ namespace System public static void ThrowIfEqual(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) where T : IEquatable? { if (EqualityComparer.Default.Equals(value, other)) - ThrowEqual(paramName, value, other); + ThrowEqual(value, other, paramName); } /// Throws an if is not equal to . @@ -178,7 +178,7 @@ namespace System public static void ThrowIfNotEqual(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null) where T : IEquatable? { if (!EqualityComparer.Default.Equals(value, other)) - ThrowNotEqual(paramName, value, other); + ThrowNotEqual(value, other, paramName); } /// Throws an if is greater than . @@ -189,7 +189,7 @@ namespace System where T : IComparable { if (value.CompareTo(other) > 0) - ThrowGreater(paramName, value, other); + ThrowGreater(value, other, paramName); } /// Throws an if is greater than or equal . @@ -200,7 +200,7 @@ namespace System where T : IComparable { if (value.CompareTo(other) >= 0) - ThrowGreaterEqual(paramName, value, other); + ThrowGreaterEqual(value, other, paramName); } /// Throws an if is less than . @@ -211,7 +211,7 @@ namespace System where T : IComparable { if (value.CompareTo(other) < 0) - ThrowLess(paramName, value, other); + ThrowLess(value, other, paramName); } /// Throws an if is less than or equal . @@ -222,7 +222,7 @@ namespace System where T : IComparable { if (value.CompareTo(other) <= 0) - ThrowLessEqual(paramName, value, other); + ThrowLessEqual(value, other, paramName); } } } -- 2.7.4