diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/http.zig | 15 | ||||
-rw-r--r-- | src/sourcemap/sourcemap.zig | 30 |
2 files changed, 16 insertions, 29 deletions
diff --git a/src/http.zig b/src/http.zig index f45477d9b..1a474a5bb 100644 --- a/src/http.zig +++ b/src/http.zig @@ -2316,22 +2316,15 @@ pub const RequestContext = struct { const SourceMapHandler = JSPrinter.SourceMapHandler.For(SocketPrinterInternal, onSourceMapChunk); pub fn onSourceMapChunk(this: *SocketPrinterInternal, chunk: SourceMap.Chunk, source: logger.Source) anyerror!void { - defer { - SocketPrinterInternal.buffer.?.* = this.buffer; - } if (this.rctx.has_called_done) return; - this.buffer.reset(); - this.buffer = try chunk.printSourceMapContents( + var mutable = try chunk.printSourceMapContents( source, - this.buffer, + MutableString.initEmpty(this.rctx.allocator), this.rctx.header("Mappings-Only") == null, false, ); - defer { - this.buffer.reset(); - SocketPrinterInternal.buffer.?.* = this.buffer; - } - const buf = this.buffer.toOwnedSliceLeaky(); + + const buf = mutable.toOwnedSliceLeaky(); if (buf.len == 0) { try this.rctx.sendNoContent(); return; diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 90a786f5d..5bfc4ca51 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -629,7 +629,6 @@ pub const LineOffsetTable = struct { var stack_fallback = std.heap.stackFallback(@sizeOf(i32) * 256, allocator); var columns_for_non_ascii = std.ArrayList(i32).initCapacity(stack_fallback.get(), 120) catch unreachable; const reset_end_index = stack_fallback.fixed_buffer_allocator.end_index; - const columns_for_non_ascii_reset = columns_for_non_ascii; var remaining = contents; while (remaining.len > 0) { @@ -645,10 +644,6 @@ pub const LineOffsetTable = struct { } if (c > 0x7F and columns_for_non_ascii.items.len == 0) { - // reset the buffers - columns_for_non_ascii = columns_for_non_ascii_reset; - stack_fallback.fixed_buffer_allocator.reset(); - stack_fallback.fixed_buffer_allocator.end_index = reset_end_index; // we have a non-ASCII character, so we need to keep track of the // mapping from byte offsets to UTF-16 code unit counts @@ -701,23 +696,22 @@ pub const LineOffsetTable = struct { remaining = remaining[1..]; continue; } - var columns_list = columns_for_non_ascii; - if (columns_for_non_ascii.items.len > 0 and stack_fallback.fixed_buffer_allocator.ownsSlice(std.mem.sliceAsBytes(columns_for_non_ascii.items))) { - columns_for_non_ascii.items = allocator.dupe(i32, columns_for_non_ascii.toOwnedSlice()) catch unreachable; - columns_for_non_ascii.capacity = columns_for_non_ascii.items.len; + + var owned = columns_for_non_ascii.toOwnedSlice(); + if (stack_fallback.fixed_buffer_allocator.ownsSlice(std.mem.sliceAsBytes(owned))) { + owned = allocator.dupe(i32, owned) catch unreachable; } list.append(allocator, .{ .byte_offset_to_start_of_line = line_byte_offset, .byte_offset_to_first_non_ascii = byte_offset_to_first_non_ascii, - .columns_for_non_ascii = BabyList(i32).fromList(columns_list), + .columns_for_non_ascii = BabyList(i32).init(owned), }) catch unreachable; column = 0; byte_offset_to_first_non_ascii = 0; column_byte_offset = 0; line_byte_offset = 0; - columns_for_non_ascii = columns_for_non_ascii_reset; stack_fallback.fixed_buffer_allocator.reset(); stack_fallback.fixed_buffer_allocator.end_index = reset_end_index; }, @@ -742,21 +736,21 @@ pub const LineOffsetTable = struct { columns_for_non_ascii.appendAssumeCapacity(column); } } - { - var columns_list = columns_for_non_ascii; - if (columns_for_non_ascii.items.len > 0 and stack_fallback.fixed_buffer_allocator.ownsSlice(std.mem.sliceAsBytes(columns_for_non_ascii.items))) { - columns_for_non_ascii.items = allocator.dupe(i32, columns_for_non_ascii.toOwnedSlice()) catch unreachable; - columns_for_non_ascii.capacity = columns_for_non_ascii.items.len; + var owned = columns_for_non_ascii.toOwnedSlice(); + if (stack_fallback.fixed_buffer_allocator.ownsSlice(std.mem.sliceAsBytes(owned))) { + owned = allocator.dupe(i32, owned) catch unreachable; } - list.append(allocator, .{ .byte_offset_to_start_of_line = line_byte_offset, .byte_offset_to_first_non_ascii = byte_offset_to_first_non_ascii, - .columns_for_non_ascii = BabyList(i32).fromList(columns_list), + .columns_for_non_ascii = BabyList(i32).init(owned), }) catch unreachable; } + if (list.capacity > list.len) { + list.shrinkAndFree(allocator, list.len); + } return list; } }; |