summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/File.zig6
-rw-r--r--src/memory.zig26
-rw-r--r--src/walk.zig6
3 files changed, 15 insertions, 23 deletions
diff --git a/src/File.zig b/src/File.zig
index 7acf8dd6..1199e2fb 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -46,7 +46,7 @@ pub const Snapshot = struct {
saved_len: ?usize = null,
fn deinit(s: Snapshot, gpa: std.mem.Allocator) void {
- pardes.memory.freeUnfilled(gpa, s.content);
+ pardes.memory.freeRaw(gpa, s.content);
}
};
@@ -818,7 +818,7 @@ pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void {
p.gpa.free(file.path);
// Raw, as every text is freed (a replica's rollback copy pins them,
// src/rollback.zig, and a safe build's free writes over what it frees).
- if (ntwins == 0) pardes.memory.freeUnfilled(p.gpa, file.content);
+ if (ntwins == 0) pardes.memory.freeRaw(p.gpa, file.content);
if (file.listing) |listing| p.gpa.free(listing.names);
if (file.mini) |*mini| mini.deinit(p.gpa);
if (file.line_starts.len > 0 and !index_shared) pardes.memory.freeRaw(p.gpa, file.line_starts);
@@ -915,7 +915,7 @@ pub fn setContentSpan(p: *Pardes, f: *State, new: []u8, span_in: ?Span) void {
}
// Raw: `free` overwrites a safe build's freed memory, a whole file's
// worth per keystroke; and its digest word goes (src/walk.zig).
- pardes.memory.freeUnfilled(p.gpa, f.content);
+ pardes.memory.freeRaw(p.gpa, f.content);
f.content = new;
f.revision +%= 1;
f.splice = .{ .revision = f.revision, .head = known.head, .tail = known.tail, .old_len = old_len };
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);
diff --git a/src/walk.zig b/src/walk.zig
index 601b1387..53d4b82c 100644
--- a/src/walk.zig
+++ b/src/walk.zig
@@ -24,7 +24,7 @@
//! // What a field holds is made with another allocator on a load.
//! .alloc = .{ .{ "image", "image" } },
//! // Immutable blobs: replaced whole, never written, freed raw
-//! // (memory.freeRaw, freeUnfilled). A digest hashes each once and
+//! // (memory.freeRaw). A digest hashes each once and
//! // folds that word in; a replica's rollback copy pins them.
//! .blob = .{ "content" },
//! };
@@ -55,7 +55,7 @@ pub fn blob(comptime T: type, comptime name: []const u8) bool {
// unit a replica replays): a 100 MB file was hashed in full each time. A
// blob of `blob_min` bytes or more is hashed once instead, its word kept by
// its address, and the digest folds the word in. The word goes when the
-// blob is freed (`forget`, from memory.freeRaw and freeUnfilled: every
+// blob is freed (`forget`, from memory.freeRaw: every
// such blob is freed raw, for the rollback copy's pins), so an address
// used again is hashed again. A Debug build hashes the bytes all the same,
// folds those in, and stops where a kept word is not their hash: a blob
@@ -1904,6 +1904,6 @@ test "a blob is hashed once and folded in as a word; one written in place is not
text[1000] = 'a';
try std.testing.expectEqual(digestOfBlob(text), wordOf(@intFromPtr(text.ptr)).?);
// Freed, its word goes: an address used again is hashed again.
- memory.freeUnfilled(gpa, text);
+ memory.freeRaw(gpa, text);
try std.testing.expect(wordOf(@intFromPtr(text.ptr)) == null);
}