aboutsummaryrefslogtreecommitdiff
path: root/lib/std/zon/Serializer.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-09-05 15:00:30 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-09-20 18:33:00 -0700
commit5ec0a7d8a5201fb35334ce62f82c5958b6ba296e (patch)
tree1874ea546d4b71e1c02f3cd37e7b2747f3f791e6 /lib/std/zon/Serializer.zig
parent9b74651cd2b799a73518de26c8293636f910c833 (diff)
downloadzig-5ec0a7d8a5201fb35334ce62f82c5958b6ba296e.tar.gz
zig-5ec0a7d8a5201fb35334ce62f82c5958b6ba296e.zip
coerce vectors to arrays rather than inline for
Diffstat (limited to 'lib/std/zon/Serializer.zig')
-rw-r--r--lib/std/zon/Serializer.zig31
1 files changed, 15 insertions, 16 deletions
diff --git a/lib/std/zon/Serializer.zig b/lib/std/zon/Serializer.zig
index 5515cc2f06..6f92a64dbd 100644
--- a/lib/std/zon/Serializer.zig
+++ b/lib/std/zon/Serializer.zig
@@ -157,13 +157,11 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
}
},
.array => {
- var container = try self.beginTuple(
- .{ .whitespace_style = .{ .fields = val.len } },
- );
- for (val) |item_val| {
- try container.fieldArbitraryDepth(item_val, options);
- }
- try container.end();
+ try valueArbitraryDepthArray(self, @TypeOf(val), &val, options);
+ },
+ .vector => |vector| {
+ const array: [vector.len]vector.child = val;
+ try valueArbitraryDepthArray(self, @TypeOf(array), &array, options);
},
.@"struct" => |@"struct"| if (@"struct".is_tuple) {
var container = try self.beginTuple(
@@ -231,20 +229,21 @@ pub fn valueArbitraryDepth(self: *Serializer, val: anytype, options: ValueOption
} else {
try self.writer.writeAll("null");
},
- .vector => |vector| {
- var container = try self.beginTuple(
- .{ .whitespace_style = .{ .fields = vector.len } },
- );
- inline for (0..vector.len) |i| {
- try container.fieldArbitraryDepth(val[i], options);
- }
- try container.end();
- },
else => comptime unreachable,
}
}
+fn valueArbitraryDepthArray(s: *Serializer, comptime A: type, array: *const A, options: ValueOptions) Error!void {
+ var container = try s.beginTuple(
+ .{ .whitespace_style = .{ .fields = array.len } },
+ );
+ for (array) |elem| {
+ try container.fieldArbitraryDepth(elem, options);
+ }
+ try container.end();
+}
+
/// Serialize an integer.
pub fn int(self: *Serializer, val: anytype) Error!void {
try self.writer.printInt(val, 10, .lower, .{});