From ce555a2fb98298c3adbe2305e61b400de40df3fc Mon Sep 17 00:00:00 2001 From: araq Date: Mon, 16 Mar 2026 07:52:43 +0100 Subject: [PATCH] address bigendian bug --- lib/system/strs_v3.nim | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/system/strs_v3.nim b/lib/system/strs_v3.nim index 9865bfbab6..ef69aae679 100644 --- a/lib/system/strs_v3.nim +++ b/lib/system/strs_v3.nim @@ -96,13 +96,11 @@ proc cmpShortInline(abytes, bbytes: uint; aslen, bslen: int): int {.inline.} = aslen - bslen template ssLen(s: SmallString): int = - ## Load slen via a direct byte access. A byte load (movzx) lets the C compiler - ## prove that slen is at offset 0, distinct from inline char writes at offsets 1+, - ## enabling register-caching of slen across char-write loops (e.g. nimAddCharV1). - when system.cpuEndian == littleEndian: - int(cast[ptr byte](unsafeAddr s.bytes)[]) - else: - int(cast[ptr byte](cast[uint](unsafeAddr s.bytes) + uint(sizeof(uint) - 1))[]) + ## Load slen via a direct byte access at offset 0 (valid on both LE and BE). + ## A byte load (movzx) lets the C compiler prove that slen is at offset 0, + ## distinct from inline char writes at offsets 1+, enabling register-caching + ## of slen across char-write loops (e.g. nimAddCharV1). + int(cast[ptr byte](unsafeAddr s.bytes)[]) template setSSLen(s: var SmallString; v: int) = # Single byte store — equivalent to old `s.slen = byte(v)`.