From a2315e8df140d8cc58da39942f471e9b8df19ba7 Mon Sep 17 00:00:00 2001 From: Taylan Kammer Date: Thu, 4 Jun 2026 18:43:55 +0200 Subject: Improve short string packing/unpacking. --- src/zisp/value.zig | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'src/zisp/value.zig') diff --git a/src/zisp/value.zig b/src/zisp/value.zig index 3450bfd..4ecc70f 100644 --- a/src/zisp/value.zig +++ b/src/zisp/value.zig @@ -272,6 +272,22 @@ pub const Value = packed union { _: u13 = non_ptr, }, + /// For initializing and reading short strings. + sstr: packed struct { + // actually [6]u8 but packed struct cannot contain arrays + bytes: u48, + _tag: u3 = 0b001, + _: u13 = non_ptr, + }, + + /// For initializing and reading small rats (rational numbers). + srat: packed struct { + q: u24, + p: u25, + _tag: u2 = 0b01, + _: u13 = non_ptr, + }, + // TODO: Use a general Small Value type registration mechanism. /// For initializing and reading characters. char: packed struct { @@ -290,22 +306,6 @@ pub const Value = packed union { _: u13 = non_ptr, }, - /// For initializing and reading short strings. - sstr: packed struct { - // actually [6]u8 but packed struct cannot contain arrays - string: u48, - _tag: u3 = 0b001, - _: u13 = non_ptr, - }, - - /// For initializing and reading small rats (rational numbers). - srat: packed struct { - q: u24, - p: u25, - _tag: u2 = 0b01, - _: u13 = non_ptr, - }, - // Disjoint masks where a specific bit or bit-group are set. // zig fmt: off const mask_sign: u64 = 1 << 63 ; // 1 sign bit @@ -329,7 +329,12 @@ pub const Value = packed union { } /// To treat the 64-bit value as an 8-byte array. - pub fn bytes(v: *const Value) *const [8]u8 { + pub fn bufRO(v: *const Value) *const [8]u8 { + return @ptrCast(v); + } + + /// To treat the 64-bit value as an 8-byte array. + pub fn bufRW(v: *Value) *[8]u8 { return @ptrCast(v); } -- cgit v1.2.3