1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Avoid recalc of string length in integer ToString

This commit is contained in:
ESH 2025-01-13 20:17:04 +01:00
parent 96c0a44a7e
commit 84b2f22846
4 changed files with 5 additions and 7 deletions

View file

@ -86,7 +86,7 @@ namespace System
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
strBuffer.Append(char8Ptr, 14 - char8Idx);
}
void ToString(String strBuffer, int minNumerals)

View file

@ -82,25 +82,23 @@ namespace System
int32 char8Idx = 20;
int64 valLeft = (int64)this;
bool isNeg = true;
int minNumeralsLeft = 0;
if (valLeft >= 0)
{
valLeft = -valLeft;
isNeg = false;
}
while ((valLeft < 0) || (minNumeralsLeft > 0))
while (valLeft < 0)
{
strChars[char8Idx] = (char8)('0' &- (valLeft % 10));
valLeft /= 10;
char8Idx--;
minNumeralsLeft--;
}
if (char8Idx == 20)
strChars[char8Idx--] = '0';
if (isNeg)
strChars[char8Idx--] = '-';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
strBuffer.Append(char8Ptr, 20 - char8Idx);
}
public static Result<int64, ParseError> Parse(StringView val, NumberStyles style = .Number, CultureInfo cultureInfo = null)

View file

@ -73,7 +73,7 @@ namespace System
if (char8Idx == 14)
strChars[char8Idx--] = '0';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
strBuffer.Append(char8Ptr, 14 - char8Idx);
}
void ToString(String strBuffer, int minNumerals)

View file

@ -85,7 +85,7 @@ namespace System
if (char8Idx == 20)
strChars[char8Idx--] = '0';
char8* char8Ptr = &strChars[char8Idx + 1];
strBuffer.Append(char8Ptr);
strBuffer.Append(char8Ptr, 20 - char8Idx);
}
public static Result<uint64, ParseError> Parse(StringView val, NumberStyles style = .Number, CultureInfo cultureInfo = null)