{"draft":null,"from":130,"to":131,"files":[{"path":"src/engine/view.ts","added":49,"removed":10,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -346,6 +346,53 @@\n \t\treturn out;\n \t}\n \n+\t/** Parent/successor traversal keeps no history-sized ancestry or sibling frontier. */\n+\t*#layoutNodes(start: number): IterableIterator<number> {\n+\t\tconst graph = this.graph;\n+\t\tif (graph.hasOrderedChildren && !this.#hasMoves) {\n+\t\t\tconst first = (parent: number, after?: number): number | undefined => {\n+\t\t\t\tfor (const n of graph.orderedChildrenN(parent, after)) if (this.#has(graph.writerSeqOf(n))) return n;\n+\t\t\t\treturn undefined;\n+\t\t\t};\n+\t\t\tlet n = first(start);\n+\t\t\twhile (n !== undefined) {\n+\t\t\t\tyield n;\n+\t\t\t\tconst child = first(n);\n+\t\t\t\tif (child !== undefined) {\n+\t\t\t\t\tn = child;\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t\tlet previous = n;\n+\t\t\t\tfor (;;) {\n+\t\t\t\t\tconst parent = graph.parentCodeOf(previous);\n+\t\t\t\t\tconst sibling = first(parent, previous);\n+\t\t\t\t\tif (sibling !== undefined) {\n+\t\t\t\t\t\tn = sibling;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t\tif (parent === start) {\n+\t\t\t\t\t\tn = undefined;\n+\t\t\t\t\t\tbreak;\n+\t\t\t\t\t}\n+\t\t\t\t\tif (parent < 0 || parent >= previous) throw new Error(\"invalid persistent layout ancestry\");\n+\t\t\t\t\tprevious = parent;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\treturn;\n+\t\t}\n+\t\tconst stack: number[] = [];\n+\t\tconst push = (parent: number): void => {\n+\t\t\tconst children = this.#children(parent);\n+\t\t\tfor (let i = children.length - 1; i >= 0; i--) stack.push(children[i]!.n);\n+\t\t};\n+\t\tpush(start);\n+\t\twhile (stack.length) {\n+\t\t\tconst n = stack.pop()!;\n+\t\t\tyield n;\n+\t\t\tpush(n);\n+\t\t}\n+\t}\n+\n \t/** Lay out one file: its line tree from the set's atoms, linearized. */\n \t#layout(path: string, complete: boolean): FileState {\n \t\tconst graph = this.graph;\n@@ -363,17 +410,10 @@\n \t\tconst seq: number[] = [];\n \t\tconst vis: number[] = [];\n \t\tconst deletedBy = new Map<number, readonly number[]>();\n-\t\t// Depth-first, iteratively (a file of n lines can be a chain n deep).\n-\t\tconst stack: number[] = [];\n-\t\tconst pushChildren = (code: number): void => {\n-\t\t\tconst list = this.#children(code);\n-\t\t\tfor (let i = list.length - 1; i >= 0; i--) stack.push(list[i]!.n);\n-\t\t};\n+\n \t\tconst start = graph.startCodeOf(path);\n-\t\tif (start !== undefined) pushChildren(start);\n \t\tconst priority = (a: number, b: number) => graph.lamportOfSeq(a) - graph.lamportOfSeq(b) || a - b;\n-\t\twhile (stack.length > 0) {\n-\t\t\tconst n = stack.pop()!;\n+\t\tfor (const n of start === undefined ? [] : this.#layoutNodes(start)) {\n \t\t\tlet deleted = false;\n \t\t\tconst by: number[] = [];\n \t\t\tfor (const deleter of graph.eachDeleterSeqOf(n)) {\n@@ -386,7 +426,6 @@\n \t\t\t\tif (complete) deletedBy.set(seq.length, by.length > 1 ? by.sort(priority) : by);\n \t\t\t} else vis.push(n);\n \t\t\tif (complete) seq.push(n);\n-\t\t\tpushChildren(n);\n \t\t}\n \t\tconst attrs: FileAttrs = {\n \t\t\texists: setters.get(\"exists\")?.value === \"1\","}],"unmatched":[]}