summaryrefslogtreecommitdiff
path: root/core/Dir.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-19 10:20:22 -0300
committerGabriel Schneider <[email protected]>2026-11-19 10:49:23 -0300
commit70c1aed30c6884024ecc2bd7f82d47e371d58ca4 (patch)
tree9c9754b0ce4e94bcb6f4de8f739a38602b4da3b0 /core/Dir.zig
parentec4956d7b4fe097cd7a9488329a14fa28a79fb7a (diff)
downloadpardes-70c1aed30c6884024ecc2bd7f82d47e371d58ca4.tar.gz
pardes-70c1aed30c6884024ecc2bd7f82d47e371d58ca4.zip
dir: a directory's listing is read through the tape it is handed (the handle's step 1, P20, pardes-handle-sizing section 3's first noun): Dir.read takes `tape: *Tape` before its allocator and its site is the tape's method (`tape.site(.dir_listing, ..)`), its two callers pass the core's (`p.tape`) and its test the tape nobody records (`&tape.none`), and the listing's body takes Zig's io as its first parameter, handed by the tape (Tape.call gives a body whose first parameter is an `std.Io` its caller does not pass the tape's own; a body whose caller still passes one, /os's stat and listing in fs.zig, keeps it until its noun), so Dir.zig no longer reads the process's io; the listing's site is recorded, replayed and refused as before. The five numbers: (1) functions that gained the parameter 1, Dir.read (row: 1), its caller lines 3 in 1 file (row: 5 in 3); (2) perfops 97 counts within 0.1%, largest image-frame on medium +0.0308% (the base's own spread), no function on a per-row path gained anything; (3) nothing stopped compiling for want of an io: the listing's body was the only reader of Dir.zig's; (4) global io uses 10 (11 before; plus the tape's field default), calls into the free functions 92 (93), machine_lines Dir.zig 2 -> 1; (5) lines changed: tests 1, code 24 (Dir.zig 12, tape.zig 11, root.zig 1). Gate: tui core-test 837/980 (143 skipped), shell-test 1015/1018, pane-test 183/184, behaviour-test 275/275 and --replay 20 seeds 0 failures, process-test lspcomplete and lspcompletemoved (the base's), replicas --clients 5 diverged 0, unequal 0, deltas wrong 0 (1731/0, 1620/0, 1737/0), quiet 545/0, 554/0, 651/0; daemon.py plain, --far, --games, --window-clients pass; semantics 2f615168fe07b35f (unmoved); frames 77/77 byte-identical in Debug, gui unit-test 1613/1617, perfab corpus2x +0.256% pictures identical in all 10 runs (under 0.4%; no operation moved, so outside pardes's own code), perfops PASS
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/Dir.zig')
-rw-r--r--core/Dir.zig13
1 files changed, 6 insertions, 7 deletions
diff --git a/core/Dir.zig b/core/Dir.zig
index 1be67378..3c74d704 100644
--- a/core/Dir.zig
+++ b/core/Dir.zig
@@ -46,17 +46,17 @@ pub fn ofName(name: []const u8) []const u8 {
/// (plan9port lib9 dirread, acme's dircmp): every name but `.` and `..`,
/// dotfiles too; a directory's, a link to one's too, ending in `/`; sorted
/// bytewise, the `/` counted; each ending in a newline.
-pub fn read(gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
+pub fn read(tape: *pardes.tape.Tape, gpa: std.mem.Allocator, dir: []const u8) ![]u8 {
if (comptime !filesystem.platform_has_fs) return error.FileNotFound;
const local = filesystem.localPath(dir) orelse return error.NotLocal;
// Its own copy: the caller's may be a pane's, gone while the turn is out.
var own: [4096]u8 = undefined;
if (local.len > own.len) return error.NameTooLong;
@memcpy(own[0..local.len], local);
- return pardes.tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
+ return tape.site(.dir_listing, gpa, readHost, .{ gpa, own[0..local.len] });
}
-fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
+fn readHost(io: std.Io, gpa: std.mem.Allocator, local: []const u8) ![]u8 {
var entries: std.ArrayList([]u8) = .empty;
defer {
for (entries.items) |entry| gpa.free(entry);
@@ -64,7 +64,6 @@ fn readHost(gpa: std.mem.Allocator, local: []const u8) ![]u8 {
}
var total: usize = 0;
{
- const io = std.Io.Threaded.global_single_threaded.io();
var d = try std.Io.Dir.cwd().openDir(io, local, .{ .iterate = true });
defer d.close(io);
var it = d.iterate();
@@ -165,7 +164,7 @@ pub fn fit(p: *Pardes, pane: *Pane, cols: usize) void {
pub fn refresh(p: *Pardes, id: usize) !void {
const pane = p.panes[id] orelse return error.NoPane;
const serial = pane.serial;
- const names = try read(p.gpa, ofName(pane.file.?.path));
+ const names = try read(p.tape, p.gpa, ofName(pane.file.?.path));
// The pane may have closed while the turn was out.
const now = p.panes[id] orelse return p.gpa.free(names);
if (now.serial != serial) return p.gpa.free(names);
@@ -195,7 +194,7 @@ pub fn look(p: *Pardes, from: usize, dir: []const u8) void {
}
var said: [limits.host_path_cap + 16]u8 = undefined;
const what = std.fmt.bufPrint(&said, "look: {s}", .{name[0..@min(name.len, limits.host_path_cap)]}) catch unreachable; // cap and 6 fit
- const names = read(p.gpa, dir) catch |err| {
+ const names = read(p.tape, p.gpa, dir) catch |err| {
p.gpa.free(name);
return p.reportError(from, what, err);
};
@@ -307,7 +306,7 @@ test "a directory reads as acme lists it: dotfiles kept, . and .. not, directori
try tmp.dir.symLink(io, "a", "link", .{ .is_directory = true });
var buf: [4096]u8 = undefined;
const dir = buf[0..try tmp.dir.realPath(io, &buf)];
- const names = try read(testing.allocator, dir);
+ const names = try read(&pardes.tape.none, testing.allocator, dir);
defer testing.allocator.free(names);
// Bytewise, as dircmp's memcmp: `.` before capitals before small
// letters, and `a.d/` before `a/` because `.` is before `/`.