Switch mimalloc guards to assertions

The thin mimalloc API is currently defensive around incorrect setup/teardown by
guarding against using/destroying the arena when the heap is null, or creating
an arena when it already exists.

The only time these checks will fail is when the code is wrong, e.g. trying
to use libdom before or after freeing the arena. The current behavior can mask
these errors, plus add runtime overhead.
This commit is contained in:
Karl Seguin
2025-08-31 19:35:53 +08:00
parent f66f4d9aeb
commit b2cf5df612
4 changed files with 18 additions and 18 deletions

View File

@@ -211,9 +211,6 @@ pub const Document = struct {
arena: std.heap.ArenaAllocator,
pub fn init(html: []const u8) !Document {
parser.deinit();
try parser.init();
var fbs = std.io.fixedBufferStream(html);
const html_doc = try parser.documentHTMLParse(fbs.reader(), "utf-8");
@@ -224,7 +221,6 @@ pub const Document = struct {
}
pub fn deinit(self: *Document) void {
parser.deinit();
self.arena.deinit();
}
@@ -375,8 +371,6 @@ pub const JsRunner = struct {
allocator: Allocator,
fn init(alloc: Allocator, opts: RunnerOpts) !JsRunner {
parser.deinit();
const browser = try alloc.create(Browser);
errdefer alloc.destroy(browser);
@@ -493,14 +487,11 @@ var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
pub var test_app: *App = undefined;
pub fn setup() !void {
try parser.init();
test_app = try App.init(gpa.allocator(), .{
.run_mode = .serve,
.tls_verify_host = false,
});
}
pub fn shutdown() void {
parser.deinit();
test_app.deinit();
}