Added a map with just the zero UUID in memory

So I dont need to create a map everytime I have a orders=none
This commit is contained in:
Adrien Bouvais 2025-01-16 22:49:36 +01:00
parent 6bd3782e1e
commit 14ea22dad6
3 changed files with 16 additions and 7 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;