diff --git a/lib/std/json/static.zig b/lib/std/json/static.zig index ea0bb6c0f2c1..312fa1a119ef 100644 --- a/lib/std/json/static.zig +++ b/lib/std/json/static.zig @@ -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,