diff options
| author | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-12 15:51:07 +0100 |
|---|---|---|
| committer | Taylan Kammer <taylan.kammer@gmail.com> | 2026-01-12 15:51:07 +0100 |
| commit | f1f134d072e375335be5c1203095115fef1db253 (patch) | |
| tree | 83114bb0e7a86feb991ddcaf61c47f0f9f2c0535 /src | |
| parent | e7379444abab7abf7a0a2e61b1f57ba0f83511a0 (diff) | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/zisp/value.zig | 2 | ||||
| -rw-r--r-- | src/zisp/value/rune.zig | 15 | ||||
| -rw-r--r-- | src/zisp/value/sstr.zig | 13 |
3 files changed, 14 insertions, 16 deletions
diff --git a/src/zisp/value.zig b/src/zisp/value.zig index 4a55677..48bd63f 100644 --- a/src/zisp/value.zig +++ b/src/zisp/value.zig @@ -182,7 +182,7 @@ pub const ShortString = struct { /// Used to find the length of a rune or short string. pub fn sstrLen(x: u64) u8 { const bytes: @Vector(8, u8) = @bitCast(x); - const nulls: @Vector(8, u8) = [_]u8{0} ** 8; + const nulls: @Vector(8, u8) = @splat(0); const comps: u8 = @bitCast(bytes == nulls); // Two bits will always be 0, since the actual short string starts at the // third byte; third lowest or third highest depending on endianness. So, diff --git a/src/zisp/value/rune.zig b/src/zisp/value/rune.zig index f49feb4..59a2d5d 100644 --- a/src/zisp/value/rune.zig +++ b/src/zisp/value/rune.zig @@ -40,18 +40,17 @@ pub fn pack(s: []const u8) Value { } pub fn packForced(s: []const u8) Value { - std.debug.assert(0 < s.len and s.len < 7); - var v = Value{ .rune = .{ .name = 0 } }; - const dest: [*]u8 = @ptrCast(&v.rune.name); - @memcpy(dest, s); - return v; + std.debug.assert(s.len <= 6); + var buf: [6]u8 = @splat(0); + @memcpy(buf[0..s.len], s); + return .{ .rune = .{ .name = @bitCast(buf) } }; } pub fn unpack(v: Value) ShortString { assert(v); - const s: [6]u8 = @bitCast(v.rune.name); - const l = value.sstrLen(v.bits); - return .{ .buf = s, .len = l }; + const buf: [6]u8 = @bitCast(v.rune.name); + const len = value.sstrLen(v.bits); + return .{ .buf = buf, .len = len }; } // Zisp API diff --git a/src/zisp/value/sstr.zig b/src/zisp/value/sstr.zig index b4cabff..7520e88 100644 --- a/src/zisp/value/sstr.zig +++ b/src/zisp/value/sstr.zig @@ -35,17 +35,16 @@ fn assertValidSstr(s: []const u8) void { pub fn pack(s: []const u8) Value { assertValidSstr(s); - var v = Value{ .sstr = .{ .string = 0 } }; - const dest: [*]u8 = @ptrCast(&v.sstr.string); - @memcpy(dest, s); - return v; + var buf: [6]u8 = @splat(0); + @memcpy(buf[0..s.len], s); + return .{ .sstr = .{ .string = @bitCast(buf) } }; } pub fn unpack(v: Value) ShortString { assert(v); - const s: [6]u8 = @bitCast(v.sstr.string); - const l = value.sstrLen(v.bits); - return .{ .buf = s, .len = l }; + const buf: [6]u8 = @bitCast(v.sstr.string); + const len = value.sstrLen(v.bits); + return .{ .buf = buf, .len = len }; } // No Zisp API for sstr specifically, since it's a string. See string.zig. |
