Skip to content

Commit

Permalink
Support big endian during fast char to byte conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Jan 10, 2025
1 parent a38cdf7 commit f5ba82f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ModTek/Features/Logging/FastBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ internal void Append(int value)
FormattingHelpers.WriteDigits(position, (uint)value, digits);
}

private static readonly int s_charLowBitsPosition = BitConverter.IsLittleEndian ? 0 : 1;
internal void Append(string value)
{
var processingCount = value.Length;
Expand All @@ -155,7 +156,7 @@ internal void Append(string value)
fixed (char* chars = value)
{
var dstPtr = _bufferPtr + _length;
var srcPtr = (byte*)chars;
var srcPtr = (byte*)chars + s_charLowBitsPosition;

// parallelism isn't what makes it particular fast, it's the batching that is helpful (fewer ops overall)
// 8 is a sweat spot, since we can do the ASCII bit mask check with an ulong
Expand Down

0 comments on commit f5ba82f

Please sign in to comment.