1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

removed unneccesary code

This commit is contained in:
Rene Schallner 2023-01-20 20:50:40 +01:00
parent 01df5ce456
commit b265b4315d
2 changed files with 1 additions and 43 deletions

View file

@ -1,5 +1,4 @@
const std = @import("std"); const std = @import("std");
const zap = @import("zap");
alloc: std.mem.Allocator = undefined, alloc: std.mem.Allocator = undefined,
users: std.AutoHashMap(usize, InternalUser) = undefined, users: std.AutoHashMap(usize, InternalUser) = undefined,
@ -129,7 +128,7 @@ pub fn toJSON(self: *Self) ![]const u8 {
} }
std.debug.assert(self.users.count() == l.items.len); std.debug.assert(self.users.count() == l.items.len);
std.debug.assert(self.count == l.items.len); std.debug.assert(self.count == l.items.len);
return zap.stringifyArrayListAlloc(self.alloc, User, &l, .{}); return std.json.stringifyAlloc(self.alloc, l.items, .{});
} }
// //

View file

@ -60,44 +60,3 @@ pub fn stringifyBuf(
return null; return null;
} }
} }
/// provide your own buf, NOT mutex-protected
pub fn stringifyArrayListBuf(
buffer: []u8,
comptime T: anytype,
list: *std.ArrayList(T),
options: std.json.StringifyOptions,
) !?[]const u8 {
var fba = std.heap.FixedBufferAllocator.init(buffer);
var string = std.ArrayList(u8).init(fba.allocator());
var writer = string.writer();
try writer.writeByte('[');
var first: bool = true;
for (list.items) |user| {
if (!first) try writer.writeByte(',');
first = false;
try std.json.stringify(user, options, string.writer());
}
try writer.writeByte(']');
return string.items;
}
/// provide your own allocator, NOT mutex-protected
pub fn stringifyArrayListAlloc(
a: std.mem.Allocator,
comptime T: anytype,
list: *std.ArrayList(T),
options: std.json.StringifyOptions,
) ![]const u8 {
var string = std.ArrayList(u8).init(a);
var writer = string.writer();
try writer.writeByte('[');
var first: bool = true;
for (list.items) |item| {
if (!first) try writer.writeByte(',');
first = false;
try std.json.stringify(item, options, string.writer());
}
try writer.writeByte(']');
return string.toOwnedSlice();
}