Skip to content

Commit 267d5e8

Browse files
committed
Revert changes to TimeSpanParse.Pow10
1 parent decf099 commit 267d5e8

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

src/libraries/System.Private.CoreLib/src/System/Globalization/DateTimeFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private static void FormatCustomized<TChar>(
485485
if (tokenLen <= MaxSecondsFractionDigits)
486486
{
487487
int fraction = (int)(dateTime.Ticks % Calendar.TicksPerSecond);
488-
fraction /= TimeSpanParse.Pow10(MaxSecondsFractionDigits - tokenLen);
488+
fraction /= (int)TimeSpanParse.Pow10(MaxSecondsFractionDigits - tokenLen);
489489
if (ch == 'f')
490490
{
491491
FormatFraction(ref result, fraction, fixedNumberFormats[tokenLen - 1]);

src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanFormat.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ private static void FormatCustomized<TChar>(TimeSpan value, scoped ReadOnlySpan<
356356
}
357357

358358
tmp = fraction;
359-
tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
359+
tmp /= (int)TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
360360
DateTimeFormat.FormatFraction(ref result, tmp, DateTimeFormat.fixedNumberFormats[tokenLen - 1]);
361361
break;
362362
case 'F':
@@ -370,7 +370,7 @@ private static void FormatCustomized<TChar>(TimeSpan value, scoped ReadOnlySpan<
370370
}
371371

372372
tmp = fraction;
373-
tmp /= TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
373+
tmp /= (int)TimeSpanParse.Pow10(DateTimeFormat.MaxSecondsFractionDigits - tokenLen);
374374
int effectiveDigits = tokenLen;
375375
while (effectiveDigits > 0)
376376
{

src/libraries/System.Private.CoreLib/src/System/Globalization/TimeSpanParse.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public bool NormalizeAndValidateFraction()
133133
// .000001 normalize to 10 ticks
134134
// .1 normalize to 1,000,000 ticks
135135

136-
_num *= Pow10(MaxFractionDigits - totalDigitsCount);
136+
_num *= (int)Pow10(MaxFractionDigits - totalDigitsCount);
137137
return true;
138138
}
139139

@@ -564,22 +564,20 @@ internal bool SetBadFormatSpecifierFailure(char? formatSpecifierCharacter = null
564564
}
565565
}
566566

567-
internal static int Pow10(int pow)
567+
internal static long Pow10(int pow)
568568
{
569-
Debug.Assert(pow >= 0);
570-
Debug.Assert(pow <= MaxFractionDigits);
571-
ReadOnlySpan<int> powersOfTen = [
572-
1,
573-
10,
574-
100,
575-
1000,
576-
10000,
577-
100000,
578-
1000000,
579-
10000000,
580-
];
581-
Debug.Assert(powersOfTen.Length == MaxFractionDigits + 1);
582-
return powersOfTen[pow];
569+
return pow switch
570+
{
571+
0 => 1,
572+
1 => 10,
573+
2 => 100,
574+
3 => 1000,
575+
4 => 10000,
576+
5 => 100000,
577+
6 => 1000000,
578+
7 => 10000000,
579+
_ => (long)Math.Pow(10, pow),
580+
};
583581
}
584582

585583
private static bool TryTimeToTicks(bool positive, TimeSpanToken days, TimeSpanToken hours, TimeSpanToken minutes, TimeSpanToken seconds, TimeSpanToken fraction, out long result)

0 commit comments

Comments
 (0)