diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 84d6f8208eebc..e9397f692bbfe 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -590,7 +590,7 @@ pub fn inspect( // we are going to always clone to keep things simple for now // the common case here will be stack-allocated, so it should be fine - var out = ZigString.init(array.toOwnedSliceLeaky()).withEncoding(); + var out = ZigString.init(array.slice()).withEncoding(); const ret = out.toJS(globalThis); array.deinit(); return ret; @@ -3932,7 +3932,7 @@ const TOMLObject = struct { return .zero; }; - const slice = writer.ctx.buffer.toOwnedSliceLeaky(); + const slice = writer.ctx.buffer.slice(); var out = bun.String.fromUTF8(slice); defer out.deref(); diff --git a/src/bun.js/api/JSBundler.zig b/src/bun.js/api/JSBundler.zig index bab8fc1a0862b..5e52a877e3060 100644 --- a/src/bun.js/api/JSBundler.zig +++ b/src/bun.js/api/JSBundler.zig @@ -557,6 +557,8 @@ pub const JSBundler = struct { self.public_path.deinit(); self.conditions.deinit(); self.drop.deinit(); + self.banner.deinit(); + self.footer.deinit(); } }; diff --git a/src/bun.js/api/html_rewriter.zig b/src/bun.js/api/html_rewriter.zig index ef86b5083f355..767662975c9a2 100644 --- a/src/bun.js/api/html_rewriter.zig +++ b/src/bun.js/api/html_rewriter.zig @@ -710,7 +710,7 @@ pub const HTMLRewriter = struct { // pub fn done(this: *StreamOutputSink) void { // var prev_value = this.response.body.value; - // var bytes = this.bytes.toOwnedSliceLeaky(); + // var bytes = this.bytes.slice(); // this.response.body.value = .{ // .Blob = JSC.WebCore.Blob.init(bytes, this.bytes.allocator, this.global), // }; diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 75b755bce1495..2fc5a560b0f3a 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3129,7 +3129,7 @@ pub const JSGlobalObject = opaque { return ZigString.static(fmt).toErrorInstance(this); // Ensure we clone it. - var str = ZigString.initUTF8(buf.toOwnedSliceLeaky()); + var str = ZigString.initUTF8(buf.slice()); return str.toErrorInstance(this); } else { @@ -3148,7 +3148,7 @@ pub const JSGlobalObject = opaque { defer buf.deinit(); var writer = buf.writer(); writer.print(fmt, args) catch return ZigString.static(fmt).toErrorInstance(this); - var str = ZigString.fromUTF8(buf.toOwnedSliceLeaky()); + var str = ZigString.fromUTF8(buf.slice()); return str.toTypeErrorInstance(this); } else { return ZigString.static(fmt).toTypeErrorInstance(this); @@ -3162,7 +3162,7 @@ pub const JSGlobalObject = opaque { defer buf.deinit(); var writer = buf.writer(); writer.print(fmt, args) catch return ZigString.static(fmt).toErrorInstance(this); - var str = ZigString.fromUTF8(buf.toOwnedSliceLeaky()); + var str = ZigString.fromUTF8(buf.slice()); return str.toSyntaxErrorInstance(this); } else { return ZigString.static(fmt).toSyntaxErrorInstance(this); @@ -3176,7 +3176,7 @@ pub const JSGlobalObject = opaque { defer buf.deinit(); var writer = buf.writer(); writer.print(fmt, args) catch return ZigString.static(fmt).toErrorInstance(this); - var str = ZigString.fromUTF8(buf.toOwnedSliceLeaky()); + var str = ZigString.fromUTF8(buf.slice()); return str.toRangeErrorInstance(this); } else { return ZigString.static(fmt).toRangeErrorInstance(this); @@ -4619,7 +4619,7 @@ pub const JSValue = enum(JSValueReprInt) { var writer = buf.writer(); try writer.print(fmt, args); - return String.init(buf.toOwnedSliceLeaky()).toJS(globalThis); + return String.init(buf.slice()).toJS(globalThis); } /// Create a JSValue string from a zig format-print (fmt + args), with pretty format @@ -4633,7 +4633,7 @@ pub const JSValue = enum(JSValueReprInt) { switch (Output.enable_ansi_colors) { inline else => |enabled| try writer.print(Output.prettyFmt(fmt, enabled), args), } - return String.init(buf.toOwnedSliceLeaky()).toJS(globalThis); + return String.init(buf.slice()).toJS(globalThis); } pub fn fromEntries(globalThis: *JSGlobalObject, keys_array: [*c]ZigString, values_array: [*c]ZigString, strings_count: usize, clone: bool) JSValue { diff --git a/src/bun.js/module_loader.zig b/src/bun.js/module_loader.zig index f597d2dbd7c30..edab5fba41ea3 100644 --- a/src/bun.js/module_loader.zig +++ b/src/bun.js/module_loader.zig @@ -2143,7 +2143,7 @@ pub const ModuleLoader = struct { writer.writeAll(";\n") catch bun.outOfMemory(); } - const public_url = bun.String.createUTF8(buf.toOwnedSliceLeaky()); + const public_url = bun.String.createUTF8(buf.slice()); return ResolvedSource{ .allocator = &jsc_vm.allocator, .source_code = public_url, diff --git a/src/bun.js/test/diff_format.zig b/src/bun.js/test/diff_format.zig index c907d16fd420f..fc04a74e33f57 100644 --- a/src/bun.js/test/diff_format.zig +++ b/src/bun.js/test/diff_format.zig @@ -129,8 +129,8 @@ pub const DiffFormatter = struct { buffered_writer.flush() catch unreachable; } - const received_slice = received_buf.toOwnedSliceLeaky(); - const expected_slice = expected_buf.toOwnedSliceLeaky(); + const received_slice = received_buf.slice(); + const expected_slice = expected_buf.slice(); if (this.not) { const not_fmt = "Expected: not {s}"; diff --git a/src/bun.js/test/expect.zig b/src/bun.js/test/expect.zig index b522dc8cfbad0..35a417ad4fb03 100644 --- a/src/bun.js/test/expect.zig +++ b/src/bun.js/test/expect.zig @@ -2757,7 +2757,7 @@ pub const Expect = struct { }; defer pretty_value.deinit(); - if (strings.eqlLong(pretty_value.toOwnedSliceLeaky(), saved_value, true)) { + if (strings.eqlLong(pretty_value.slice(), saved_value, true)) { Jest.runner.?.snapshots.passed += 1; return .undefined; } @@ -2766,7 +2766,7 @@ pub const Expect = struct { const signature = comptime getSignature("toMatchSnapshot", "expected", false); const fmt = signature ++ "\n\n{any}\n"; const diff_format = DiffFormatter{ - .received_string = pretty_value.toOwnedSliceLeaky(), + .received_string = pretty_value.slice(), .expected_string = saved_value, .globalThis = globalThis, }; @@ -5443,7 +5443,7 @@ pub const ExpectCustomAsymmetricMatcher = struct { return .zero; }; if (printed) { - return bun.String.init(mutable_string.toOwnedSliceLeaky()).toJS(); + return bun.String.init(mutable_string.slice()).toJS(); } return ExpectMatcherUtils.printValue(globalThis, this, null); } diff --git a/src/bun.js/test/jest.zig b/src/bun.js/test/jest.zig index a7d370f35eb0b..ace7a2172a526 100644 --- a/src/bun.js/test/jest.zig +++ b/src/bun.js/test/jest.zig @@ -1788,7 +1788,7 @@ inline fn createScope( buffer.reset(); appendParentLabel(&buffer, parent) catch @panic("Bun ran out of memory while filtering tests"); buffer.append(label) catch unreachable; - const str = bun.String.fromBytes(buffer.toOwnedSliceLeaky()); + const str = bun.String.fromBytes(buffer.slice()); is_skip = !regex.matches(str); if (is_skip) { tag_to_use = .skip; @@ -2087,7 +2087,7 @@ fn eachBind( buffer.reset(); appendParentLabel(&buffer, parent) catch @panic("Bun ran out of memory while filtering tests"); buffer.append(formattedLabel) catch unreachable; - const str = bun.String.fromBytes(buffer.toOwnedSliceLeaky()); + const str = bun.String.fromBytes(buffer.slice()); is_skip = !regex.matches(str); } diff --git a/src/bun.js/web_worker.zig b/src/bun.js/web_worker.zig index 7f64f84842acf..848b84dfde7e5 100644 --- a/src/bun.js/web_worker.zig +++ b/src/bun.js/web_worker.zig @@ -331,7 +331,7 @@ pub const WebWorker = struct { bun.outOfMemory(); }; JSC.markBinding(@src()); - WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.createUTF8(array.toOwnedSliceLeaky()), error_instance); + WebWorker__dispatchError(globalObject, worker.cpp_worker, bun.String.createUTF8(array.slice()), error_instance); if (vm.worker) |worker_| { _ = worker.setRequestedTerminate(); worker.parent_poll_ref.unrefConcurrently(worker.parent); diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 77efafd485dea..450086c12c717 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -1439,7 +1439,7 @@ pub const BundleV2 = struct { .entry_points = config.entry_points.keys(), .target = config.target.toAPI(), .absolute_working_dir = if (config.dir.list.items.len > 0) - config.dir.toOwnedSliceLeaky() + config.dir.slice() else null, .inject = &.{}, @@ -1467,8 +1467,8 @@ pub const BundleV2 = struct { bundler.options.output_format = config.format; bundler.options.bytecode = config.bytecode; - bundler.options.output_dir = config.outdir.toOwnedSliceLeaky(); - bundler.options.root_dir = config.rootdir.toOwnedSliceLeaky(); + bundler.options.output_dir = config.outdir.slice(); + bundler.options.root_dir = config.rootdir.slice(); bundler.options.minify_syntax = config.minify.syntax; bundler.options.minify_whitespace = config.minify.whitespace; bundler.options.minify_identifiers = config.minify.identifiers; @@ -1479,8 +1479,8 @@ pub const BundleV2 = struct { bundler.options.emit_dce_annotations = config.emit_dce_annotations orelse !config.minify.whitespace; bundler.options.ignore_dce_annotations = config.ignore_dce_annotations; bundler.options.experimental_css = config.experimental_css; - bundler.options.banner = config.banner.toOwnedSliceLeaky(); - bundler.options.footer = config.footer.toOwnedSliceLeaky(); + bundler.options.banner = config.banner.slice(); + bundler.options.footer = config.footer.slice(); bundler.configureLinker(); try bundler.configureDefines(); @@ -1546,7 +1546,7 @@ pub const BundleV2 = struct { bun.default_allocator.dupe( u8, bun.path.joinAbsString( - this.config.outdir.toOwnedSliceLeaky(), + this.config.outdir.slice(), &[_]string{output_file.dest_path}, .auto, ), @@ -1556,7 +1556,7 @@ pub const BundleV2 = struct { u8, bun.path.joinAbsString( Fs.FileSystem.instance.top_level_dir, - &[_]string{ this.config.dir.toOwnedSliceLeaky(), this.config.outdir.toOwnedSliceLeaky(), output_file.dest_path }, + &[_]string{ this.config.dir.slice(), this.config.outdir.slice(), output_file.dest_path }, .auto, ), ) catch unreachable @@ -8951,7 +8951,7 @@ pub const LinkerContext = struct { const input = c.parse_graph.input_files.items(.source)[chunk.entry_point.source_index].path; var buf = MutableString.initEmpty(worker.allocator); js_printer.quoteForJSONBuffer(input.pretty, &buf, true) catch bun.outOfMemory(); - const str = buf.toOwnedSliceLeaky(); // worker.allocator is an arena + const str = buf.slice(); // worker.allocator is an arena j.pushStatic(str); line_offset.advance(str); } diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index c75452a0fdfd4..65c4a4c744a4c 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -559,7 +559,7 @@ pub const UpgradeCommand = struct { else => return error.HTTPError, } - const bytes = zip_file_buffer.toOwnedSliceLeaky(); + const bytes = zip_file_buffer.slice(); progress.end(); refresher.refresh(); diff --git a/src/js_printer.zig b/src/js_printer.zig index 08199425c23ff..25100aa707914 100644 --- a/src/js_printer.zig +++ b/src/js_printer.zig @@ -5804,7 +5804,7 @@ const FileWriterInternal = struct { ctx: *FileWriterInternal, ) anyerror!void { defer buffer.reset(); - const result_ = buffer.toOwnedSliceLeaky(); + const result_ = buffer.slice(); var result = result_; while (result.len > 0) { @@ -5955,9 +5955,9 @@ pub const BufferWriter = struct { if (ctx.append_null_byte) { ctx.sentinel = ctx.buffer.toOwnedSentinelLeaky(); - ctx.written = ctx.buffer.toOwnedSliceLeaky(); + ctx.written = ctx.buffer.slice(); } else { - ctx.written = ctx.buffer.toOwnedSliceLeaky(); + ctx.written = ctx.buffer.slice(); } } diff --git a/src/renamer.zig b/src/renamer.zig index 64e9e93e56ea6..c41e4ca66c2f8 100644 --- a/src/renamer.zig +++ b/src/renamer.zig @@ -751,9 +751,9 @@ pub const NumberRenamer = struct { mutable_name.appendSlice(prefix) catch unreachable; mutable_name.appendInt(tries) catch unreachable; - switch (NameUse.find(this, mutable_name.toOwnedSliceLeaky())) { + switch (NameUse.find(this, mutable_name.slice())) { .unused => { - name = mutable_name.toOwnedSliceLeaky(); + name = mutable_name.slice(); if (use == .same_scope) { const existing = this.name_counts.getOrPut(allocator, prefix) catch unreachable; @@ -775,7 +775,7 @@ pub const NumberRenamer = struct { tries += 1; - switch (NameUse.find(this, mutable_name.toOwnedSliceLeaky())) { + switch (NameUse.find(this, mutable_name.slice())) { .unused => { if (cur_use == .same_scope) { const existing = this.name_counts.getOrPut(allocator, prefix) catch unreachable; @@ -790,7 +790,7 @@ pub const NumberRenamer = struct { existing.value_ptr.* = tries; } - name = mutable_name.toOwnedSliceLeaky(); + name = mutable_name.slice(); break; }, else => {}, @@ -847,7 +847,7 @@ pub const ExportRenamer = struct { var writer = this.string_buffer.writer(); writer.print("{s}{d}", .{ input, tries }) catch unreachable; tries += 1; - const attempt = this.string_buffer.toOwnedSliceLeaky(); + const attempt = this.string_buffer.slice(); entry = this.used.getOrPut(attempt) catch unreachable; if (!entry.found_existing) { const to_use = this.string_buffer.allocator.dupe(u8, attempt) catch unreachable; diff --git a/src/sourcemap/CodeCoverage.zig b/src/sourcemap/CodeCoverage.zig index eb3b4e0343d70..52d3624143ff4 100644 --- a/src/sourcemap/CodeCoverage.zig +++ b/src/sourcemap/CodeCoverage.zig @@ -695,7 +695,7 @@ pub const ByteRangeMapping = struct { return .zero; }; - var str = bun.String.createUTF8(mutable_str.toOwnedSliceLeaky()); + var str = bun.String.createUTF8(mutable_str.slice()); defer str.deref(); return str.toJS(globalThis); } diff --git a/src/string_mutable.zig b/src/string_mutable.zig index d787c9a3ab2e2..49d248dc9c1da 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -172,17 +172,16 @@ pub const MutableString = struct { try self.list.ensureUnusedCapacity(self.allocator, amount); } - pub inline fn appendSlice(self: *MutableString, slice: []const u8) !void { - try self.list.appendSlice(self.allocator, slice); + pub inline fn appendSlice(self: *MutableString, items: []const u8) !void { + try self.list.appendSlice(self.allocator, items); } - pub inline fn appendSliceExact(self: *MutableString, slice: []const u8) !void { + pub inline fn appendSliceExact(self: *MutableString, items: []const u8) !void { if (slice.len == 0) return; - - try self.list.ensureTotalCapacityPrecise(self.allocator, self.list.items.len + slice.len); + try self.list.ensureTotalCapacityPrecise(self.allocator, self.list.items.len + items.len); var end = self.list.items.ptr + self.list.items.len; - self.list.items.len += slice.len; - @memcpy(end[0..slice.len], slice); + self.list.items.len += items.len; + @memcpy(end[0..items.len], items); } pub inline fn reset( @@ -237,7 +236,7 @@ pub const MutableString = struct { return self.list.toOwnedSlice(self.allocator) catch bun.outOfMemory(); // TODO } - pub fn toOwnedSliceLeaky(self: *MutableString) []u8 { + pub fn slice(self: *MutableString) []u8 { return self.list.items; } @@ -264,10 +263,6 @@ pub const MutableString = struct { return self.list.toOwnedSlice(self.allocator) catch bun.outOfMemory(); // TODO } - // pub fn deleteAt(self: *MutableString, i: usize) { - // self.list.swapRemove(i); - // } - pub fn containsChar(self: *const MutableString, char: u8) bool { return self.indexOfChar(char) != null; }