From f5ba82f807bc4a6c0963ab1f7523bb933063a475 Mon Sep 17 00:00:00 2001 From: CptMoore <39010654+cptmoore@users.noreply.github.com> Date: Fri, 10 Jan 2025 07:49:57 +0100 Subject: [PATCH] Support big endian during fast char to byte conversion. --- ModTek/Features/Logging/FastBuffer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ModTek/Features/Logging/FastBuffer.cs b/ModTek/Features/Logging/FastBuffer.cs index ed6fdabf..e93a41cd 100644 --- a/ModTek/Features/Logging/FastBuffer.cs +++ b/ModTek/Features/Logging/FastBuffer.cs @@ -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; @@ -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