Update string serialization to always write length prefix
- Always write length prefix before ASCII and UTF-8 strings in AcBinarySerializer for consistency and correctness. - Increase release warmup iterations from 2000 to 3000 in Program.cs.
This commit is contained in:
parent
11e71336b0
commit
9973b6be12
|
|
@ -49,7 +49,7 @@ public static class Program
|
|||
private static int WarmupIterations = 5;
|
||||
private static int TestIterations = 10;
|
||||
#else
|
||||
private static int WarmupIterations = 2000;
|
||||
private static int WarmupIterations = 3000;
|
||||
private static int TestIterations = 1000;
|
||||
|
||||
//private static int WarmupIterations = 5000;
|
||||
|
|
|
|||
|
|
@ -487,6 +487,7 @@ public static partial class AcBinarySerializer
|
|||
// Single-pass Ascii.FromUtf16 (scan+copy combined) instead of
|
||||
// Ascii.IsValid (scan) + Ascii.FromUtf16 (scan+copy) = double traversal
|
||||
var savedPosition = _position;
|
||||
|
||||
WriteVarUInt((uint)charLength);
|
||||
EnsureCapacity(charLength);
|
||||
|
||||
|
|
@ -500,8 +501,10 @@ public static partial class AcBinarySerializer
|
|||
// FromUtf16 fails fast on first non-ASCII char, so speculative cost is minimal
|
||||
_position = savedPosition;
|
||||
var byteCount = Utf8NoBom.GetByteCount(value);
|
||||
|
||||
WriteVarUInt((uint)byteCount);
|
||||
EnsureCapacity(byteCount);
|
||||
|
||||
Utf8NoBom.GetBytes(value.AsSpan(), _buffer.AsSpan(_position, byteCount));
|
||||
_position += byteCount;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue