From 5cd677299dab89276d55b938fda3fbe99bb1e3ec Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Fri, 7 Nov 2025 15:04:03 +0000 Subject: [PATCH] Add memoryCost method to CompressedVariant for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make CompressedVariant consistent with AnyBlob and Headers by giving it its own memoryCost() method instead of accessing .data.len directly. This makes the code more maintainable and consistent with how other types in StaticRoute report their memory usage. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/bun.js/api/server/StaticRoute.zig | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/bun.js/api/server/StaticRoute.zig b/src/bun.js/api/server/StaticRoute.zig index 294a7ed313..94004bbe4c 100644 --- a/src/bun.js/api/server/StaticRoute.zig +++ b/src/bun.js/api/server/StaticRoute.zig @@ -14,6 +14,10 @@ pub const CompressedVariant = struct { pub fn deinit(this: *CompressedVariant, allocator: std.mem.Allocator) void { allocator.free(this.data); } + + pub fn memoryCost(this: *const CompressedVariant) usize { + return this.data.len; + } }; pub const CompressionFailed = struct {}; @@ -120,27 +124,31 @@ pub fn clone(this: *StaticRoute, globalThis: *jsc.JSGlobalObject) !*StaticRoute }); } -pub fn memoryCost(this: *const StaticRoute) usize { - var cost = @sizeOf(StaticRoute) + this.blob.memoryCost() + this.headers.memoryCost(); +fn compressedMemoryCost(this: *const StaticRoute) usize { + var cost: usize = 0; switch (this.compressed_br) { - .cached => |variant| cost += variant.data.len, + .cached => |variant| cost += variant.memoryCost(), else => {}, } switch (this.compressed_gzip) { - .cached => |variant| cost += variant.data.len, + .cached => |variant| cost += variant.memoryCost(), else => {}, } switch (this.compressed_zstd) { - .cached => |variant| cost += variant.data.len, + .cached => |variant| cost += variant.memoryCost(), else => {}, } switch (this.compressed_deflate) { - .cached => |variant| cost += variant.data.len, + .cached => |variant| cost += variant.memoryCost(), else => {}, } return cost; } +pub fn memoryCost(this: *const StaticRoute) usize { + return @sizeOf(StaticRoute) + this.blob.memoryCost() + this.headers.memoryCost() + this.compressedMemoryCost(); +} + pub fn fromJS(globalThis: *jsc.JSGlobalObject, argument: jsc.JSValue) bun.JSError!?*StaticRoute { if (argument.as(jsc.WebCore.Response)) |response| {