summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:42:03 -0300
committerGabriel Schneider <[email protected]>2026-11-05 00:58:29 -0300
commit673c9a6d03fedafc8c7a973fa3af0a3b026d10d8 (patch)
tree0361f8ad48e4690961718edee55e108192e2ff10
parent66c4095e140694376fd07c3afa0fee721558bdb3 (diff)
downloadpardes-673c9a6d03fedafc8c7a973fa3af0a3b026d10d8.tar.gz
pardes-673c9a6d03fedafc8c7a973fa3af0a3b026d10d8.zip
ninep tree: releaseHandle looks its pane up once and switches on the file, where five blocks each looked it up again and a sixth after them; lookup parses a pane's and a column's directory serial once; changesPane is needsQuiet plus the two it adds; readdir's two one-caller stagers are inline; name_capacity, read only by its own assert, and e_bad_addr, by nothing, go
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/ninep/tree.zig122
1 files changed, 47 insertions, 75 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index a5444caa..3d715c51 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -29,13 +29,6 @@ const Pardes = pardes.Pardes;
const Pane = pardes.Pane;
const MAX_PANES = pardes.MAX_PANES;
-pub const name_capacity: usize = 255;
-
-comptime {
- // The editor's engine (src/9p.zig) remembers names this long.
- std.debug.assert(@import("../9p.zig").editor.name_capacity == name_capacity);
-}
-
// ---- the backend contract: cloud9.fs, with the editor's payload locator ----
pub const Op = cloud9.fs.Op;
@@ -61,7 +54,6 @@ pub fn failText(tag: u64, errno: u16, text: []const u8) Reply {
return .{ .tag = tag, .status = .err, .errno = errno, .ename = text };
}
-pub const e_bad_addr = "bad address syntax";
pub const e_bad_ctl = "ill-formed control message";
pub const e_bad_event = "bad event syntax";
/// A second open reading a file whose reads consume: rio's word for it
@@ -110,16 +102,13 @@ fn truncates(req: Req) bool {
};
}
-/// `needsQuiet`, plus the open that makes a pane: what costs a frame and a
-/// wake of the editor.
+/// `needsQuiet`, plus the open that makes a pane and a close that hands
+/// held text on: what costs a frame and a wake of the editor.
pub fn changesPane(p: *Pardes, req: Req) bool {
- return switch (req.op) {
- .write => true,
- .setattr => truncates(req),
+ return needsQuiet(p, req) or switch (req.op) {
.open => req.node == @backingInt(TopFile.new),
- .release => req.remove or holdsLines(p, req) or holdsPage(p, req),
- .read => holdsPage(p, req),
- .lookup, .getattr, .readdir => false,
+ .release => holdsLines(p, req) or holdsPage(p, req),
+ else => false,
};
}
@@ -739,22 +728,15 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
if (sources.node(name)) |n| return sources.handle(p, .{ .tag = req.tag, .op = .getattr, .node = n });
return Reply.fail(req.tag, E.NOENT);
},
- .pane => pane: {
- if (std.mem.eql(u8, name, new_pane)) break :pane @backingInt(TopFile.new);
- // A pane directory is its serial, in decimal digits and never 0.
+ .pane, .col => dir: {
+ if (f == .pane and std.mem.eql(u8, name, new_pane)) break :dir @backingInt(TopFile.new);
+ // A pane's or a column's directory is its serial, in decimal
+ // digits and never 0.
if (name.len > 10) return Reply.fail(req.tag, E.NOENT);
for (name) |c| if (c < '0' or c > '9') return Reply.fail(req.tag, E.NOENT);
const serial = std.fmt.parseInt(u32, name, 10) catch return Reply.fail(req.tag, E.NOENT);
if (serial == 0) return Reply.fail(req.tag, E.NOENT);
- break :pane Node.of(serial, .dir);
- },
- // A column is its serial, in decimal digits and never 0.
- .col => col: {
- if (name.len > 10) return Reply.fail(req.tag, E.NOENT);
- for (name) |c| if (c < '0' or c > '9') return Reply.fail(req.tag, E.NOENT);
- const serial = std.fmt.parseInt(u32, name, 10) catch return Reply.fail(req.tag, E.NOENT);
- if (serial == 0) return Reply.fail(req.tag, E.NOENT);
- break :col Node.ofCol(serial, .dir);
+ break :dir if (f == .pane) Node.of(serial, .dir) else Node.ofCol(serial, .dir);
},
else => return Reply.fail(req.tag, E.NOTDIR),
},
@@ -778,23 +760,6 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply {
return .{ .tag = req.tag, .attr = attrOf(p, found) orelse return Reply.fail(req.tag, E.NOENT) };
}
-fn stagePaneFiles(p: *Pardes, out: *std.ArrayList(u8), serial: u32, terminal: bool, skip: *u64) void {
- inline for (comptime std.enums.values(PaneFile)) |f| {
- if (comptime f == .dir or (f.inPty() and f != .pty)) continue;
- const present = f != .pty or terminal;
- if (present) {
- if (skip.* > 0) skip.* -= 1 else stageDirent(out, p.gpa, Node.of(serial, f), f.isDir(), f.fileName());
- }
- }
-}
-
-fn stagePtyFiles(p: *Pardes, out: *std.ArrayList(u8), serial: u32, skip: *u64) void {
- inline for (comptime std.enums.values(PaneFile)) |f| {
- if (comptime !f.inPty() or f == .pty) continue;
- if (skip.* > 0) skip.* -= 1 else stageDirent(out, p.gpa, Node.of(serial, f), false, f.fileName());
- }
-}
-
fn readdir(p: *Pardes, req: Req, target: Target) Reply {
const out = p.fs.stage(p.gpa);
var skip = req.off;
@@ -847,10 +812,19 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
const id = p.paneBySerial(t.serial) orelse return Reply.fail(req.tag, E.NOENT);
const terminal = p.panes[id].?.isTerminal();
switch (t.file) {
- .dir => stagePaneFiles(p, out, t.serial, terminal, &skip),
+ // The pty files are listed inside pty/, and it only on a terminal.
+ .dir => inline for (comptime std.enums.values(PaneFile)) |f| {
+ if (comptime f == .dir or (f.inPty() and f != .pty)) continue;
+ if (f != .pty or terminal) {
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, Node.of(t.serial, f), f.isDir(), f.fileName());
+ }
+ },
.pty => {
if (!terminal) return Reply.fail(req.tag, E.NOENT);
- stagePtyFiles(p, out, t.serial, &skip);
+ inline for (comptime std.enums.values(PaneFile)) |f| {
+ if (comptime !f.inPty() or f == .pty) continue;
+ if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, Node.of(t.serial, f), false, f.fileName());
+ }
},
else => return Reply.fail(req.tag, E.NOTDIR),
}
@@ -980,33 +954,32 @@ fn release(p: *Pardes, req: Req) Reply {
/// the connection it came on.
fn releaseHandle(p: *Pardes, req: Req) void {
const t = Node.target(req.node).?;
- // A truncating write to `tag` is over when its open goes (pane.zig
- // writeTag): a newline it held back is dropped.
- if (t == .pane and t.pane.file == .tag) if (p.paneBySerial(t.pane.serial)) |id| {
- pane.applyTagTruncation(p, p.panes[id].?);
- p.panes[id].?.fs.tag_rewrite = false;
- p.panes[id].?.fs.tag_held_newline = false;
- };
- // The writes of one open are one undo step (pane.zig `joined`): its
- // close ends that step.
- // A sel open's run of writes ends with it.
- if (t == .pane and t.pane.file == .sel) if (p.paneBySerial(t.pane.serial)) |id| {
- const pf = &p.panes[id].?.fs;
- if (pf.wrsel_by == req.handle) pf.wrsel_by = 0;
- };
- if (t == .pane and (t.pane.file == .body or t.pane.file == .data or t.pane.file == .xdata)) if (p.paneBySerial(t.pane.serial)) |id| {
- const pf = &p.panes[id].?.fs;
- if (pf.joined_by == 0 or pf.joined_by == req.handle) pf.joined = null;
- };
- // `: > limit` clears it for good once its open goes.
- if (t == .pane and t.pane.file == .limit) if (p.paneBySerial(t.pane.serial)) |id| {
- p.panes[id].?.fs.limit_truncated = null;
- };
- // `: > dot` empties it once its open goes, no write having set it.
- if (t == .pane and t.pane.file == .dot) if (p.paneBySerial(t.pane.serial)) |id| {
- const pn = p.panes[id].?;
- if (pn.fs.dot_truncated) pane.setDot(pn, .{});
- pn.fs.dot_truncated = false;
+ const of: ?*Pane = if (t == .pane) (if (p.paneBySerial(t.pane.serial)) |id| p.panes[id] else null) else null;
+ if (of) |pn| switch (t.pane.file) {
+ // A truncating write to `tag` is over when its open goes (pane.zig
+ // writeTag): a newline it held back is dropped.
+ .tag => {
+ pane.applyTagTruncation(p, pn);
+ pn.fs.tag_rewrite = false;
+ pn.fs.tag_held_newline = false;
+ },
+ // A sel open's run of writes ends with it.
+ .sel => if (pn.fs.wrsel_by == req.handle) {
+ pn.fs.wrsel_by = 0;
+ },
+ // The writes of one open are one undo step (pane.zig `joined`): its
+ // close ends that step.
+ .body, .data, .xdata => if (pn.fs.joined_by == 0 or pn.fs.joined_by == req.handle) {
+ pn.fs.joined = null;
+ },
+ // `: > limit` clears it for good once its open goes.
+ .limit => pn.fs.limit_truncated = null,
+ // `: > dot` empties it once its open goes, no write having set it.
+ .dot => {
+ if (pn.fs.dot_truncated) pane.setDot(pn, .{});
+ pn.fs.dot_truncated = false;
+ },
+ else => {},
};
if (t == .col and t.col.file == .tag) cols.released(p, t.col.serial);
if (t == .top and t.top == .tag) cols.released(p, null);
@@ -1023,7 +996,6 @@ fn releaseHandle(p: *Pardes, req: Req) void {
p.fs.closed_lines.append(p.gpa, .{ .node = req.node, .bytes = o.pending }) catch o.pending.deinit(p.gpa);
o.pending = .empty;
}
- const of: ?*Pane = if (t == .pane) (if (p.paneBySerial(t.pane.serial)) |id| p.panes[id] else null) else null;
if (of) |pn| switch (o.what) {
.event => |reader| {
if (reader) pn.fs.event_reader = false;