removed some stuff

This commit is contained in:
yuzu 2025-05-25 19:19:15 -05:00
parent 2f307f3c37
commit f54b34dded

View File

@ -49,20 +49,15 @@ pub const JsonInput = union(JsonType) {
pub fn deinit(self: JsonInput, allocator: mem.Allocator) void {
switch (self) {
JsonInput.array => |array| {
for (array) |json_input| {
for (array) |json_input|
json_input.deinit(allocator);
}
allocator.free(array);
},
.object => |*object| {
var it = object.iterator();
while (it.next()) |entry| {
entry.value_ptr.deinit(allocator);
//allocator.free(entry.key_ptr.*);
}
while (it.next()) |entry| entry.value_ptr.deinit(allocator);
@constCast(object).deinit(allocator);
},
.string => |_| {},
else => {},
}
}
@ -161,25 +156,9 @@ fn addString(self: *Self, allocator: mem.Allocator, bytes: []const u8) !usize {
return idx;
}
fn addEmptyObject(self: *Self, allocator: mem.Allocator) !usize {
fn addEmpty(self: *Self, allocator: mem.Allocator) !usize {
try self.index.ensureUnusedCapacity(allocator, 1);
const idx = self.index.addOneAssumeCapacity();
const object: ObjectEntry = .{
.property_idx = self.property_index.string_bytes.items.len,
.value_idx = self.index.len + 1,
.len = 0,
};
self.index.set(idx, .{ .object = object });
return idx;
}
fn addEmptyArray(self: *Self, allocator: mem.Allocator) !usize {
try self.index.ensureUnusedCapacity(allocator, 1);
const idx = self.index.addOneAssumeCapacity();
self.index.set(idx, .{ .array = ArraySlice{
.start = self.index.len,
.len = 0,
} });
return idx;
}
@ -252,9 +231,9 @@ fn getValue(
const entry = self.index.get(idx);
switch (entry) {
.null => return .null,
.bool => return .{ .bool = entry.bool },
.number => return .{ .number = entry.number },
.null => return .{ .null = {} },
.bool => |b| return .{ .bool = b },
.number => |number| return .{ .number = number },
.string => |string| {
const sl = string.slice(&self.string_index);
return .{ .string = sl };
@ -333,7 +312,7 @@ pub fn parse(self: *Self, tokenizer: *Tokenizer) !usize {
var it = tokenizer.iterator();
const root = try self.addEmptyObject(allocator);
const root = try self.addEmpty(allocator);
var token = it.next() orelse
return root;
@ -343,6 +322,7 @@ pub fn parse(self: *Self, tokenizer: *Tokenizer) !usize {
flag: switch (token.type) {
.eof => {
assert(query.slice().len == 0);
assert(root == 0);
return root;
},
.property => {
@ -391,7 +371,7 @@ pub fn parse(self: *Self, tokenizer: *Tokenizer) !usize {
const parent_idx = query.get(query.len - 1);
const idx_ptr = try query.addOne();
idx_ptr.* = try self.addEmptyObject(allocator);
idx_ptr.* = try self.addEmpty(allocator);
self.index.set(idx_ptr.*, .{
.object = ObjectEntry{
.len = 0,
@ -438,7 +418,7 @@ pub fn parse(self: *Self, tokenizer: *Tokenizer) !usize {
const idx_ptr = try query.addOne();
idx_ptr.* = try self.addEmptyArray(allocator);
idx_ptr.* = try self.addEmpty(allocator);
self.index.set(idx_ptr.*, .{ .array = ArraySlice{
.len = 0,
.start = idx_ptr.* + 1,