Skip to content

Commit

Permalink
Use string.TryCopyTo
Browse files Browse the repository at this point in the history
  • Loading branch information
xtqqczze committed Oct 6, 2024
1 parent 1a4c249 commit d1f0cc0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/libraries/System.Private.CoreLib/src/System/Boolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,17 @@ public bool TryFormat(Span<char> destination, out int charsWritten)
{
if (m_value)
{
if (destination.Length >= 4)
if (TrueLiteral.TryCopyTo(destination))
{
ulong true_val = BitConverter.IsLittleEndian ? 0x65007500720054ul : 0x54007200750065ul; // "True"
Unsafe.WriteUnaligned(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(destination)), true_val);
charsWritten = 4;
charsWritten = TrueLiteral.Length;
return true;
}
}
else
{
if (destination.Length >= 5)
if (FalseLiteral.TryCopyTo(destination))
{
ulong fals_val = BitConverter.IsLittleEndian ? 0x73006C00610046ul : 0x460061006C0073ul; // "Fals"
Unsafe.WriteUnaligned(ref Unsafe.As<char, byte>(ref MemoryMarshal.GetReference(destination)), fals_val);
destination[4] = 'e';
charsWritten = 5;
charsWritten = FalseLiteral.Length;
return true;
}
}
Expand Down

0 comments on commit d1f0cc0

Please sign in to comment.