Parse and write at the same time
Created a new function to replace parseAndFindUUIDWithFilter. Now it parse the file, evaluate with the filter and write directly to a buffer. There is no UUID that is return, then file are parse again. Should be a huge perf improve. Some bugs with additionData tho, got a name: "<UUID>" =(
This commit is contained in:
@@ -39,7 +39,6 @@ pub fn parseBool(value_str: []const u8) bool {
|
||||
return (value_str[0] != '0');
|
||||
}
|
||||
|
||||
// TODO: Optimize all date parsing
|
||||
pub fn parseDate(value_str: []const u8) DateTime {
|
||||
const year: u16 = std.fmt.parseInt(u16, value_str[0..4], 10) catch 0;
|
||||
const month: u16 = std.fmt.parseInt(u16, value_str[5..7], 10) catch 0;
|
||||
@@ -178,8 +177,7 @@ pub fn parseArrayStr(allocator: std.mem.Allocator, array_str: []const u8) std.Ar
|
||||
_ = it.next(); // SSkip first token that is empty
|
||||
while (it.next()) |x| {
|
||||
if (std.mem.eql(u8, " ", x)) continue;
|
||||
const x_copy = std.fmt.allocPrint(allocator, "'{s}'", .{x}) catch @panic("=(");
|
||||
array.append(x_copy) catch {};
|
||||
array.append(x) catch {};
|
||||
}
|
||||
|
||||
if (array.items.len > 0) allocator.free(array.pop()); // Remove the last because empty like the first one
|
||||
|
||||
@@ -44,6 +44,19 @@ pub const UUID = struct {
|
||||
return buf;
|
||||
}
|
||||
|
||||
pub fn format_bytes(bytes: [16]u8) [36]u8 {
|
||||
var buf: [36]u8 = undefined;
|
||||
buf[8] = '-';
|
||||
buf[13] = '-';
|
||||
buf[18] = '-';
|
||||
buf[23] = '-';
|
||||
inline for (encoded_pos, 0..) |i, j| {
|
||||
buf[i + 0] = hex[bytes[j] >> 4];
|
||||
buf[i + 1] = hex[bytes[j] & 0x0f];
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
// Indices in the UUID string representation for each byte.
|
||||
const encoded_pos = [16]u8{ 0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34 };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user