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:
parent
6bd3782e1e
commit
14ea22dad6
@ -329,7 +329,6 @@ fn deleteEntitiesOneFile(
|
|||||||
return;
|
return;
|
||||||
}) |row| {
|
}) |row| {
|
||||||
if (!finish_writing and (filter == null or filter.?.evaluate(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| {
|
writer.print("{{\"{s}\"}},", .{UUID.format_bytes(row[0].UUID)}) catch |err| {
|
||||||
sync_context.logError("Error writting", err);
|
sync_context.logError("Error writting", err);
|
||||||
return;
|
return;
|
||||||
|
@ -92,6 +92,8 @@ pub fn parse(self: *Self, buffer: [:0]const u8) ZipponError!void {
|
|||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
const allocator = arena.allocator();
|
const allocator = arena.allocator();
|
||||||
|
|
||||||
|
try @import("parts/value.zig").initZeroMap();
|
||||||
|
|
||||||
toker = Tokenizer.init(buffer);
|
toker = Tokenizer.init(buffer);
|
||||||
self.toker = &toker;
|
self.toker = &toker;
|
||||||
|
|
||||||
|
@ -10,8 +10,18 @@ const printError = @import("../../utils.zig").printError;
|
|||||||
|
|
||||||
const ZipponError = @import("error").ZipponError;
|
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");
|
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
|
/// 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 {
|
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;
|
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);
|
token.* = try self.checkTokensInArray(tag);
|
||||||
} else {
|
} else {
|
||||||
if (token.tag != tag) {
|
if (token.tag != tag) {
|
||||||
|
const msg = std.fmt.bufPrint(&buff, "Error: Wrong type. Expected: {any}", .{tag}) catch return ZipponError.MemoryError;
|
||||||
return printError(
|
return printError(
|
||||||
"Error: Wrong type", // TODO: Print the expected type
|
msg,
|
||||||
ZipponError.SynthaxError,
|
ZipponError.SynthaxError,
|
||||||
self.toker.buffer,
|
self.toker.buffer,
|
||||||
token.loc.start,
|
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]),
|
.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]),
|
.datetime_array => return try ConditionValue.initArrayDateTime(allocator, self.toker.buffer[start_index..token.loc.end]),
|
||||||
.link => switch (token.tag) {
|
.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
|
.keyword_none => {
|
||||||
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;
|
|
||||||
_ = self.toker.next();
|
_ = self.toker.next();
|
||||||
return ConditionValue.initLink(map);
|
return ConditionValue.initLink(&zero_map);
|
||||||
},
|
},
|
||||||
.uuid_literal => {
|
.uuid_literal => {
|
||||||
const uuid = UUID.parse(self.toker.buffer[start_index..token.loc.end]) catch return ZipponError.InvalidUUID;
|
const uuid = UUID.parse(self.toker.buffer[start_index..token.loc.end]) catch return ZipponError.InvalidUUID;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user