diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:12:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:00:59 -0300 |
| commit | b283824eed0703ae9b89f2af520354046146b855 (patch) | |
| tree | a791b93be7849d4ab5a804cf9e9118eba406474b /src/memory.zig | |
| parent | 2f2fd5f6cf52800f931fd62e539c2b4ed5d80ebc (diff) | |
| download | pardes-b283824eed0703ae9b89f2af520354046146b855.tar.gz pardes-b283824eed0703ae9b89f2af520354046146b855.zip | |
memory: freeUnfilled, freeRaw for a slice of u8 written out again, goes; its callers (File.zig's three, walk.zig's, memory.zig's tests) call freeRaw, and walk.zig's comments name it alone
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/memory.zig')
| -rw-r--r-- | src/memory.zig | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/memory.zig b/src/memory.zig index c1b24e6f..8ce3ad12 100644 --- a/src/memory.zig +++ b/src/memory.zig @@ -411,23 +411,15 @@ pub fn dupeUnfilled(allocator: Allocator, bytes: []const u8) Allocator.Error![]u return out; } -/// Frees without the safe-build overwrite `free` does, for text-sized buffers -/// freed on every edit. -pub fn freeUnfilled(allocator: Allocator, bytes: []const u8) void { - if (bytes.len == 0) return; - // A blob's digest word goes with it (walk.zig). - walk.forget(@intFromPtr(bytes.ptr)); - if (pinned(allocator, bytes, .of(u8))) return; - allocator.rawFree(@constCast(bytes), .of(u8), @returnAddress()); -} - -/// `freeUnfilled` for a slice of any element: a text's line index, made -/// anew at every edit too (and pinned by a replica's rollback copy, -/// src/rollback.zig, which a safe build's overwrite would spoil). +/// Frees without the safe-build overwrite `free` does: text-sized buffers +/// freed on every edit, and a text's line index, made anew at every edit +/// too (and pinned by a replica's rollback copy, src/rollback.zig, which a +/// safe build's overwrite would spoil). pub fn freeRaw(allocator: Allocator, items: anytype) void { const E = @typeInfo(@TypeOf(items)).pointer.child; const bytes = std.mem.sliceAsBytes(items); if (bytes.len == 0) return; + // A blob's digest word goes with it (walk.zig). walk.forget(@intFromPtr(bytes.ptr)); if (pinned(allocator, bytes, .of(E))) return; allocator.rawFree(@constCast(bytes), .of(E), @returnAddress()); @@ -569,16 +561,16 @@ test "arenas are separate, reuse what is freed, spill, and restart" { // it was the last one, so an arena filled once and spilled after. const big = try unfilled(allocs.pardes, 8 * MiB); const after = try allocs.pardes.alloc(u8, 32); - freeUnfilled(allocs.pardes, big); + freeRaw(allocs.pardes, big); const again = try unfilled(allocs.pardes, 8 * MiB); try std.testing.expectEqual(big.ptr, again.ptr); const spill = try unfilled(allocs.pardes, limits.arena.pardes + 1); try std.testing.expect(!pardes_region.pages.owns(spill.ptr)); try std.testing.expectEqual(limits.arena.pardes + 1, pardes_region.pages.spilled); - freeUnfilled(allocs.pardes, spill); + freeRaw(allocs.pardes, spill); try std.testing.expectEqual(0, pardes_region.pages.spilled); - freeUnfilled(allocs.pardes, again); + freeRaw(allocs.pardes, again); allocs.pardes.free(after); allocs.frame.free(frame); allocs.pardes.free(core); @@ -631,7 +623,7 @@ test "a pinned blob's free is put off until its last pin goes" { @memset(b, 7); pin(b); pin(b); - freeUnfilled(gpa, b); + freeRaw(gpa, b); // Still the blob's: a join's writer reads it. try std.testing.expectEqual(@as(u8, 7), b[100]); unpin(b); |
