Skip to content

Commit

Permalink
std: work around compiler unable to evaluate condition at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Mar 21, 2024
1 parent 2583b38 commit 7741aca
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions lib/std/json/static.zig
Original file line number Diff line number Diff line change
Expand Up @@ -400,24 +400,20 @@ pub fn innerParse(
@memcpy(r[i..][0..slice.len], slice);
i += slice.len;
},
.partial_string_escaped_1 => |arr| {
inline .partial_string_escaped_1,
.partial_string_escaped_2,
.partial_string_escaped_3,
.partial_string_escaped_4,
=> |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_2 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_3 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
@memcpy(r[i..][0..arr.len], arr[0..]);
i += arr.len;
},
.partial_string_escaped_4 => |arr| {
if (i + arr.len > r.len) return error.LengthMismatch;
@memcpy(r[i..][0..arr.len], arr[0..]);

// Implementing https://github.com/ziglang/zig/issues/3806
// would make this no longer needed because the
// above condition would become compile-time
// known.
if (arr.len > r.len) unreachable;

@memcpy(r[i..][0..arr.len], &arr);
i += arr.len;
},
else => unreachable,
Expand Down

0 comments on commit 7741aca

Please sign in to comment.