Skip to content

Commit

Permalink
Small code cleanups to make it clearer.
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Dec 23, 2024
1 parent fff0463 commit 8d6ea33
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ModTek/Features/Logging/FastBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ internal void Append(decimal value)
Append(value.ToString(CultureInfo.InvariantCulture));
}

const byte AsciiCompatibleWithUnicodeEqualsOrSmallerThan = 127;
internal void Append(string value)
{
var processingCount = value.Length;
Expand All @@ -88,6 +87,7 @@ internal void Append(string value)
// loop unrolling similar to Buffer.memcpy1
// parallelism isn't what makes it particular fast, it's the batching that is helpful (fewer ops overall)

// 8 is a sweat spot, for large amounts of data 4 is slower, 16 is slower
{
const int IterSize = 8;
for (; processingCount >= IterSize; processingCount -= IterSize)
Expand Down Expand Up @@ -151,21 +151,21 @@ internal void Append(string value)

Utf8Fallback: // this is 10x slower or more (GetBytes has no fast ASCII path and no SIMD in this old .NET)
UTF8FallbackStopwatch.Start();
var charIndex = value.Length - processingCount;
const int Utf8MaxBytesPerChar = 4;
EnsureCapacity(_length + processingCount * Utf8MaxBytesPerChar);
var charIndex = value.Length - processingCount;
_length += Encoding.UTF8.GetBytes(value, charIndex, processingCount, _buffer, _length);
UTF8FallbackStopwatch.Stop();
}
}
internal static readonly MTStopwatch UTF8FallbackStopwatch = new() { SkipFirstNumberOfMeasurements = 0 };

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetAscii(byte* positionIterPtr, char* charsIterPtr, int offset, out bool isAscii)
private void SetAscii(byte* positionIterPtr, char* charsIterPtr, int offset, out bool isUnicodeCompatibleAscii)
{
var valueAsByte = (byte)charsIterPtr[offset];
positionIterPtr[offset] = valueAsByte;
isAscii = valueAsByte <= AsciiCompatibleWithUnicodeEqualsOrSmallerThan;
isUnicodeCompatibleAscii = valueAsByte <= 127;
}

internal void Append(DateTime value)
Expand Down

0 comments on commit 8d6ea33

Please sign in to comment.