From a5d0bcf19f778ac3cc579320c64adc4cf2e5f1d7 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sun, 6 Dec 2020 12:42:39 -0800 Subject: [PATCH] Delete redundant DivMod implementation (#45652) --- .../Text/Utf8Formatter/FormattingHelpers.cs | 26 ---------------------- .../Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs | 9 ++++---- .../Text/Json/Writer/JsonWriterHelper.Date.cs | 11 +++++---- 3 files changed, 10 insertions(+), 36 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs index 2a6019d..6316a19 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/FormattingHelpers.cs @@ -149,32 +149,6 @@ namespace System.Buffers.Text #endregion UTF-8 Helper methods - #region Math Helper methods - - /// - /// We don't have access to Math.DivRem, so this is a copy of the implementation. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong DivMod(ulong numerator, ulong denominator, out ulong modulo) - { - ulong div = numerator / denominator; - modulo = numerator - (div * denominator); - return div; - } - - /// - /// We don't have access to Math.DivRem, so this is a copy of the implementation. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static uint DivMod(uint numerator, uint denominator, out uint modulo) - { - uint div = numerator / denominator; - modulo = numerator - (div * denominator); - return div; - } - - #endregion Math Helper methods - // // Enable use of ThrowHelper from TryFormat() routines without introducing dozens of non-code-coveraged "bytesWritten = 0; return false" boilerplate. // diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs index 6e4fc4f..3fa8e67 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Utf8Formatter/Utf8Formatter.TimeSpan.cs @@ -70,7 +70,8 @@ namespace System.Buffers.Text } } - totalSecondsRemaining = FormattingHelpers.DivMod((ulong)Math.Abs(value.Ticks), TimeSpan.TicksPerSecond, out ulong fraction64); + ulong fraction64; + (totalSecondsRemaining, fraction64) = Math.DivRem((ulong)Math.Abs(value.Ticks), TimeSpan.TicksPerSecond); fraction = (uint)fraction64; } @@ -114,7 +115,7 @@ namespace System.Buffers.Text if (totalSecondsRemaining > 0) { // Only compute minutes if the TimeSpan has an absolute value of >= 1 minute. - totalMinutesRemaining = FormattingHelpers.DivMod(totalSecondsRemaining, 60 /* seconds per minute */, out seconds); + (totalMinutesRemaining, seconds) = Math.DivRem(totalSecondsRemaining, 60 /* seconds per minute */); } Debug.Assert(seconds < 60); @@ -124,7 +125,7 @@ namespace System.Buffers.Text if (totalMinutesRemaining > 0) { // Only compute hours if the TimeSpan has an absolute value of >= 1 hour. - totalHoursRemaining = FormattingHelpers.DivMod(totalMinutesRemaining, 60 /* minutes per hour */, out minutes); + (totalHoursRemaining, minutes) = Math.DivRem(totalMinutesRemaining, 60 /* minutes per hour */); } Debug.Assert(minutes < 60); @@ -137,7 +138,7 @@ namespace System.Buffers.Text if (totalHoursRemaining > 0) { // Only compute days if the TimeSpan has an absolute value of >= 1 day. - days = FormattingHelpers.DivMod((uint)totalHoursRemaining, 24 /* hours per day */, out hours); + (days, hours) = Math.DivRem((uint)totalHoursRemaining, 24 /* hours per day */); } Debug.Assert(hours < 24); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs index d153241..6cf3561 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/JsonWriterHelper.Date.cs @@ -69,7 +69,7 @@ namespace System.Text.Json // Remove trailing zeros while (true) { - uint quotient = DivMod(fraction, 10, out uint remainder); + (uint quotient, uint remainder) = DivRem(fraction, 10); if (remainder != 0) { break; @@ -132,14 +132,13 @@ namespace System.Text.Json } } - // We don't have access to System.Buffers.Text.FormattingHelpers.DivMod, + // We don't always have access to System.Math.DivRem, // so this is a copy of the implementation. [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint DivMod(uint numerator, uint denominator, out uint modulo) + public static (uint Quotient, uint Remainder) DivRem(uint left, uint right) { - uint div = numerator / denominator; - modulo = numerator - (div * denominator); - return div; + uint quotient = left / right; + return (quotient, left - (quotient * right)); } } } -- 2.7.4