From 14ea22dad63c7f9b9efde2852a831f62fb61debc Mon Sep 17 00:00:00 2001 From: MrBounty Date: Thu, 16 Jan 2025 22:49:36 +0100 Subject: [PATCH] Added a map with just the zero UUID in memory So I dont need to create a map everytime I have a orders=none --- src/file/write.zig | 1 - src/ziql/parser.zig | 2 ++ src/ziql/parts/value.zig | 20 ++++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/file/write.zig b/src/file/write.zig index 82e8f8c..7df0aa1 100644 --- a/src/file/write.zig +++ b/src/file/write.zig @@ -329,7 +329,6 @@ fn deleteEntitiesOneFile( return; }) |row| { if (!finish_writing and (filter == null or filter.?.evaluate(row))) { - // _ = sstruct.uuid_file_index.map.remove(UUID{ .bytes = row[0].UUID }); FIXME: This doesnt work in multithread because they try to remove at the same time writer.print("{{\"{s}\"}},", .{UUID.format_bytes(row[0].UUID)}) catch |err| { sync_context.logError("Error writting", err); return; diff --git a/src/ziql/parser.zig b/src/ziql/parser.zig index 381059a..65d1481 100644 --- a/src/ziql/parser.zig +++ b/src/ziql/parser.zig @@ -92,6 +92,8 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void { defer arena.deinit(); const allocator = arena.allocator(); + try @import("parts/value.zig").initZeroMap(); + toker = Tokenizer.init(buffer); self.toker = &toker; diff --git a/src/ziql/parts/value.zig b/src/ziql/parts/value.zig index fa8bb61..2d8d9a4 100644 --- a/src/ziql/parts/value.zig +++ b/src/ziql/parts/value.zig @@ -10,8 +10,18 @@ const printError = @import("../../utils.zig").printError; const ZipponError = @import("error").ZipponError; +var buff: [1024]u8 = undefined; + +var zero_map_buf: [1024 * 4]u8 = undefined; +var fba = std.heap.FixedBufferAllocator.init(&zero_map_buf); +var zero_map = std.AutoHashMap(UUID, void).init(fba.allocator()); + const Self = @import("../parser.zig"); +pub fn initZeroMap() ZipponError!void { + zero_map.put(dtype.Zero, {}) catch return ZipponError.MemoryError; +} + /// To run just after a condition like = or > or >= to get the corresponding ConditionValue that you need to compare pub fn parseConditionValue(self: Self, allocator: Allocator, struct_name: []const u8, member_name: []const u8, data_type: dtype.DataType, token: *Token) ZipponError!ConditionValue { const start_index = token.loc.start; @@ -32,8 +42,9 @@ pub fn parseConditionValue(self: Self, allocator: Allocator, struct_name: []cons token.* = try self.checkTokensInArray(tag); } else { if (token.tag != tag) { + const msg = std.fmt.bufPrint(&buff, "Error: Wrong type. Expected: {any}", .{tag}) catch return ZipponError.MemoryError; return printError( - "Error: Wrong type", // TODO: Print the expected type + msg, ZipponError.SynthaxError, self.toker.buffer, token.loc.start, @@ -155,12 +166,9 @@ pub fn parseConditionValue(self: Self, allocator: Allocator, struct_name: []cons .time_array => return try ConditionValue.initArrayTime(allocator, self.toker.buffer[start_index..token.loc.end]), .datetime_array => return try ConditionValue.initArrayDateTime(allocator, self.toker.buffer[start_index..token.loc.end]), .link => switch (token.tag) { - .keyword_none => { // TODO: Stop creating a map if empty, can be null or something. Or maybe just keep one map link that in memory, so I dont create it everytime - const map = allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError; - map.* = std.AutoHashMap(UUID, void).init(allocator); - map.put(dtype.Zero, {}) catch return ZipponError.MemoryError; + .keyword_none => { _ = self.toker.next(); - return ConditionValue.initLink(map); + return ConditionValue.initLink(&zero_map); }, .uuid_literal => { const uuid = UUID.parse(self.toker.buffer[start_index..token.loc.end]) catch return ZipponError.InvalidUUID;