From c40b95b8f938e01b7e8846bae53f16b0c1cd5654 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 10 Nov 2026 03:35:02 -0300 Subject: syntax: a file's kept tree is told each edit (File.edit, ts_tree_edit) and the next parse starts from it, so a new line's indent in a 9k-line Zig file costs the 0.2 ms of what the edit touched, not the 47 ms of a parse anew (3.5 ms → 0.5 ms for 400 lines); not while a rollback copy holds the tree, which an edit in place would change under the copy: that one is left as it was and parsed anew, as is one whose revision moved without it (a twin's edit), by node_tree_edits, the revision its edits reach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- src/normal.zig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/normal.zig') diff --git a/src/normal.zig b/src/normal.zig index fc6da633..e95a5798 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -207,9 +207,11 @@ pub fn appendSearchLiteral(out: *std.ArrayList(u8), arena: std.mem.Allocator, te /// kept until the next: never made again for a key that changed nothing. pub fn fileTree(p: *Pardes, f: *panes.File.State) ?*anyopaque { if (f.node_tree == null or f.node_tree_revision != f.revision) { - if (f.node_tree) |old| syntax.freeTree(old); - f.node_tree = syntax.parseTree(f.path, f.content); + const old = f.node_tree; + f.node_tree = syntax.parseTree(f.path, f.content, if (f.node_tree_edits == f.revision) old else null); + if (old) |o| syntax.freeTree(o); f.node_tree_revision = f.revision; + f.node_tree_edits = f.revision; for (f.node_history.items) |step| p.gpa.free(step.ranges); f.node_history.clearRetainingCapacity(); } -- cgit v1.3