diff options
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r-- | src/string_immutable.zig | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 3aaec1314..fd5bcb00a 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -1480,9 +1480,12 @@ pub fn convertUTF16ToUTF8(list_: std.ArrayList(u8), comptime Type: type, utf16: pub fn toUTF8AllocWithType(allocator: std.mem.Allocator, comptime Type: type, utf16: Type) ![]u8 { if (bun.FeatureFlags.use_simdutf and comptime Type == []const u16) { const length = bun.simdutf.length.utf8.from.utf16.le(utf16); - // add 4 bytes of padding for SIMDUTF - var list = try std.ArrayList(u8).initCapacity(allocator, length + 4); + // add 16 bytes of padding for SIMDUTF + var list = try std.ArrayList(u8).initCapacity(allocator, length + 16); list = try convertUTF16ToUTF8(list, Type, utf16); + if (Environment.allow_assert) { + std.debug.assert(list.items.len == length); + } return list.items; } @@ -1496,7 +1499,11 @@ pub fn toUTF8ListWithType(list_: std.ArrayList(u8), comptime Type: type, utf16: var list = list_; const length = bun.simdutf.length.utf8.from.utf16.le(utf16); try list.ensureTotalCapacityPrecise(length + 16); - return convertUTF16ToUTF8(list, Type, utf16); + const buf = try convertUTF16ToUTF8(list, Type, utf16); + if (Environment.allow_assert) { + std.debug.assert(buf.items.len == length); + } + return buf; } return toUTF8ListWithTypeBun(list_, Type, utf16); |