Remove .string branch if using .alloc_always

This commit is contained in:
mitteneer 2025-07-09 12:09:45 -04:00
parent 902fcd4447
commit 6aac0bff2b

View file

@ -102,6 +102,7 @@ pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.U
_ = try scanner.next(); _ = try scanner.next();
try scanner.skipValue(); try scanner.skipValue();
const lfw_date_token = try scanner.nextAlloc(allocator, .alloc_if_needed); const lfw_date_token = try scanner.nextAlloc(allocator, .alloc_if_needed);
// Skip over human-readable date format and then leave
try scanner.skipValue(); try scanner.skipValue();
try scanner.skipValue(); try scanner.skipValue();
_ = try scanner.next(); _ = try scanner.next();
@ -148,7 +149,7 @@ pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.U
freeAllocated(allocator, key_token); freeAllocated(allocator, key_token);
const track = try scanner.nextAlloc(allocator, .alloc_always); const track = try scanner.nextAlloc(allocator, .alloc_always);
@field(r, "track") = switch (track) { @field(r, "track") = switch (track) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
.null => null, .null => null,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };
@ -165,13 +166,13 @@ pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.U
// Leave object // Leave object
_ = try scanner.next(); _ = try scanner.next();
break :blk switch (lfw_artist_token) { break :blk switch (lfw_artist_token) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };
} else blk: { } else blk: {
const artist_token = try scanner.nextAlloc(allocator, .alloc_always); const artist_token = try scanner.nextAlloc(allocator, .alloc_always);
break :blk switch (artist_token) { break :blk switch (artist_token) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
.null => null, .null => null,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };
@ -191,13 +192,13 @@ pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.U
// Leave object // Leave object
_ = try scanner.next(); _ = try scanner.next();
break :blk switch (lfw_album_token) { break :blk switch (lfw_album_token) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };
} else blk: { } else blk: {
const album_token = try scanner.nextAlloc(allocator, .alloc_always); const album_token = try scanner.nextAlloc(allocator, .alloc_always);
break :blk switch (album_token) { break :blk switch (album_token) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
.null => null, .null => null,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };
@ -208,7 +209,7 @@ pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.U
freeAllocated(allocator, key_token); freeAllocated(allocator, key_token);
const reason_end = try scanner.nextAlloc(allocator, .alloc_always); const reason_end = try scanner.nextAlloc(allocator, .alloc_always);
@field(r, "reason_end") = switch (reason_end) { @field(r, "reason_end") = switch (reason_end) {
inline .string, .allocated_string => |slice| slice, .allocated_string => |slice| slice,
.null => null, .null => null,
else => return error.UnexpectedToken, else => return error.UnexpectedToken,
}; };