summaryrefslogtreecommitdiff
path: root/src/zisp/value/sstr.zig
diff options
context:
space:
mode:
authorTaylan Kammer <taylan.kammer@gmail.com>2025-04-05 17:11:29 +0200
committerTaylan Kammer <taylan.kammer@gmail.com>2025-04-05 17:11:29 +0200
commit70089dacfa6bab5a1e1d0d5aa257e2d671493beb (patch)
tree913b19c94792e2d41fdc800d728ad0bdabf0fada /src/zisp/value/sstr.zig
parentcf934006c650d3d008a4408bedbd95597f906e43 (diff)
uhhhh buncha changes
Diffstat (limited to 'src/zisp/value/sstr.zig')
-rw-r--r--src/zisp/value/sstr.zig39
1 files changed, 6 insertions, 33 deletions
diff --git a/src/zisp/value/sstr.zig b/src/zisp/value/sstr.zig
index b02fd3d..4f0336e 100644
--- a/src/zisp/value/sstr.zig
+++ b/src/zisp/value/sstr.zig
@@ -3,13 +3,12 @@ const std = @import("std");
const value = @import("../value.zig");
const ShortString = value.ShortString;
-const OtherTag = value.OtherTag;
const Value = value.Value;
// Zig API
pub fn check(v: Value) bool {
- return v.isOtherTag(.sstr) or v.isOtherTag(.qstr);
+ return v.isSstr();
}
pub fn assert(v: Value) void {
@@ -19,21 +18,11 @@ pub fn assert(v: Value) void {
}
}
-pub fn checkQuoted(v: Value) bool {
- return v.isOtherTag(.qstr);
-}
-
// For now, ignore encoding, just treat it as []u8.
pub fn isValidSstr(s: []const u8) bool {
- if (s.len > 6) {
- return false;
- }
- for (s) |c| {
- if (c == 0) {
- return false;
- }
- }
+ if (s.len > 6) return false;
+ for (s) |c| if (c == 0) return false;
return true;
}
@@ -44,23 +33,9 @@ fn assertValidSstr(s: []const u8) void {
}
}
-// Different ways of doing the following have been tested, including manual
-// shifting and bit masking, but memcpy always wins easily according to our
-// micro-benchmarks, under both ReleaseSafe and ReleaseFast.
-
-// Note: rune.zig uses equivalent code; probably good to keep in sync.
-
pub fn pack(s: []const u8) Value {
- return _pack(s, .sstr);
-}
-
-pub fn packQuoted(s: []const u8) Value {
- return _pack(s, .qstr);
-}
-
-fn _pack(s: []const u8, tag: OtherTag) Value {
assertValidSstr(s);
- var v = Value{ .sstr = .{ .string = 0, .tag = tag } };
+ var v = Value{ .sstr = .{ .string = 0 } };
const dest: [*]u8 = @ptrCast(&v.sstr.string);
@memcpy(dest, s);
return v;
@@ -69,10 +44,8 @@ fn _pack(s: []const u8, tag: OtherTag) Value {
pub fn unpack(v: Value) ShortString {
assert(v);
const s: [6]u8 = @bitCast(v.sstr.string);
- inline for (0..6) |i| {
- if (s[i] == 0) return .{ .buffer = s, .len = i };
- }
- return .{ .buffer = s, .len = 6 };
+ const l = value.sstrLen(v.bits);
+ return .{ .buffer = s, .len = l };
}
// No Zisp API for sstr specifically, since it's a string. See string.zig.