{"draft":null,"from":215,"to":216,"files":[{"path":"src/engine/view.ts","added":55,"removed":5,"diff":"--- a/src/engine/view.ts\n+++ b/src/engine/view.ts\n@@ -295,6 +295,8 @@\n \t */\n \t#relocations(): Map<LineId, RelocationInfo> {\n \t\tif (this.#relocs) return this.#relocs;\n+\t\tthis.#takeShared();\n+\t\tif (this.#relocs) return this.#relocs;\n \t\tconst graph = this.graph;\n \t\tconst skeleton = skeletonOf(graph);\n \t\tconst stronger = (a: RelocationInfo, b: RelocationInfo): boolean => graph.comparePriority(a.atom, b.atom) > 0;\n@@ -365,13 +367,25 @@\n \t\treturn this.#relocs;\n \t}\n \n+\t/** The view whose moves this one may take, until it needs them all; then the view it took them from. */\n+\t#movesFrom: View | undefined;\n+\t#movesTaken: View | undefined;\n+\n \t/**\n \t * Take another view's resolved moves (abso Capacity), when both sets hold the very same atoms that move lines: the\n-\t * moves then resolve the same, and every line sits where it sits there. Checked here, so any caller may ask.\n+\t * moves then resolve the same, and every line sits where it sits there. Checked when this view first needs all its\n+\t * moves, so any caller may ask, and a view that only finds a few lines' files never resolves them.\n \t */\n \tshareMoves(from: View): void {\n-\t\tif (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves) return;\n-\t\tif (this.#relocs || from.#scratchMoves()) return;\n+\t\tif (from.graph !== this.graph || from.#hasMoves !== this.#hasMoves || !this.#hasMoves || this.#relocs) return;\n+\t\tthis.#movesFrom = from;\n+\t}\n+\n+\t#takeShared(): void {\n+\t\tconst from = this.#movesFrom;\n+\t\tif (!from) return;\n+\t\tthis.#movesFrom = undefined;\n+\t\tif (from.#scratchMoves()) return;\n \t\tfor (const id of this.graph.movers()) {\n \t\t\tconst seq = seqOf(id);\n \t\t\tif (this.#has(seq) !== from.#has(seq)) return;\n@@ -379,9 +393,29 @@\n \t\tthis.#relocs = from.#relocations();\n \t\tthis.#relocsN = from.#relocationsN();\n \t\tthis.#movesOnDisk = false;\n-\t\tthis.#movedFrom = from.#movedInFrom();\n+\t\tthis.#movesTaken = from;\n \t}\n \n+\t/** Moved lines' relocations picked one at a time, before the view resolves them all (null: not moved here). */\n+\treadonly #picked = new Map<number, MoveEntry | null>();\n+\n+\t/**\n+\t * The relocation of moved line n that counts here, as #relocations picks it before any loop: right whenever the\n+\t * walk that reached n goes on to a file's start, since only lines on a loop have their relocation set aside.\n+\t */\n+\t#pickOne(n: number): MoveEntry | undefined {\n+\t\tlet picked = this.#picked.get(n);\n+\t\tif (picked === undefined) {\n+\t\t\tconst graph = this.graph;\n+\t\t\tlet best: MoveEntry | undefined;\n+\t\t\tfor (const e of skeletonOf(graph).byLine.get(n) ?? []) {\n+\t\t\t\tif (this.#has(seqOf(e.r.atom)) && (!best || graph.comparePriority(e.r.atom, best.r.atom) > 0)) best = e;\n+\t\t\t}\n+\t\t\tthis.#picked.set(n, (picked = best ?? null));\n+\t\t}\n+\t\treturn picked ?? undefined;\n+\t}\n+\n \t/** Whether moves are resolved on disk for each layout: only a stored graph's view with more than MOVED_LINES_KEPT. */\n \t#scratchMoves(): boolean {\n \t\tif (!this.#hasMoves || !this.graph.hasOrderedChildren) return false;\n@@ -453,8 +487,21 @@\n \t/** The file a node sits in, in this set: up by where lines were written, through the moves that count here. */\n \t#fileOfCode(code: number): string {\n \t\tconst graph = this.graph;\n-\t\tconst relocs = this.#relocationsN();\n \t\tconst skeleton = skeletonOf(graph);\n+\t\tif (!this.#relocsN) {\n+\t\t\t// One moved line at a time, until a walk comes back to a line it passed: then moves loop, and are resolved whole.\n+\t\t\tconst passed = new Set<number>();\n+\t\t\tlet c = code;\n+\t\t\tfor (;;) {\n+\t\t\t\tc = skeleton.climb(c);\n+\t\t\t\tif (c < 0) return graph.nodeOf(c).slice(1);\n+\t\t\t\tif (passed.has(c)) break;\n+\t\t\t\tpassed.add(c);\n+\t\t\t\tconst e = this.#pickOne(c);\n+\t\t\t\tc = e ? e.parent : graph.parentCodeOf(c);\n+\t\t\t}\n+\t\t}\n+\t\tconst relocs = this.#relocationsN();\n \t\tlet c = code;\n \t\tfor (;;) {\n \t\t\tc = skeleton.climb(c);\n@@ -569,6 +616,8 @@\n \t#movedFrom: Map<string, Set<number>> | undefined;\n \t#movedInFrom(): Map<string, Set<number>> {\n \t\tif (this.#movedFrom) return this.#movedFrom;\n+\t\tthis.#relocations();\n+\t\tif (this.#movesTaken) return (this.#movedFrom = this.#movesTaken.#movedInFrom());\n \t\tconst graph = this.graph;\n \t\tconst out = new Map<string, Set<number>>();\n \t\tif (this.#hasMoves) {\n@@ -962,6 +1011,7 @@\n \t\tif (this.#knownList) n += ARRAY_HEADER_BYTES + REFERENCE_BYTES * this.#knownList.length;\n \t\tif (this.#relocs) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * this.#relocs.size;\n \t\tif (this.#relocsN) n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + OBJECT_BYTES) * this.#relocsN.size;\n+\t\tn += MAP_ENTRY_BYTES * this.#picked.size;\n \t\tfor (const f of this.#files.values()) {\n \t\t\tn += MAP_ENTRY_BYTES;\n \t\t\tif (f !== NO_FILE) {"}],"unmatched":[]}