Lines 10–16 at 232 (were 10–16 at 231)
1010// made when a caller asks for them, and the latest asked for is kept. 1212import type { Graph, RelocationInfo } from "./graph.ts"; 13−import { isStartNode, seqOf } from "./keys.ts";
13+import { isStartNode, lineId, seqOf } from "./keys.ts"; 1414import { resolveScratchMoves, scratchLayoutNodes } from "./relocation-scratch.ts"; 1515import { isClosedSet, StableSet } from "./state-source.ts"; 1616import { joinLines } from "./text.ts"; Lines 71–81 at 232 (were 71–76 at 231)
7171 readonly visText?: readonly (string | null)[]; 7272 /** Its visible lines' writers' seqs, when laid out from the file's packed history. */ 7373 readonly visWriter?: Int32Array; 74+ /** Its visible lines' places in their writers (a line id's k), when laid out from packed history. */ 75+ readonly visK?: Int32Array; 76+ /** The same for every line of seq, when complete and laid out from packed history. */ 77+ readonly seqWriter?: Int32Array; 78+ readonly seqK?: Int32Array; 7479 /** Positions by n, built the first time they're asked for. */ 7580 seqIndex?: Map<number, number>; 7681 visIndex?: Map<number, number>; Lines 653–659 at 232 (were 648–653 at 231)
648653 const children = new Map<number, Child[]>(); 649654 const texts = new Map<number, string | null>(); 650655 const writers = new Map<number, number>(); 656+ const places = new Map<number, number>(); 651657 const deleters = new Map<number, number[]>(); 652658 // Each atom's lamport once per layout: most lines share a few atoms, and a stored graph reads it from a page. 653659 const lamports = new Map<number, number>(); Lines 683–689 at 232 (were 677–682 at 231)
677683 else children.set(at, [child]); 678684 texts.set(n, text); 679685 writers.set(n, seq); 681688 for (const [n, deleter] of graph.packedDeletes(file)) { 682689 if (!this.#has(deleter)) continue; Lines 701–709 at 232 (were 694–699 at 231)
694701 const vis: number[] = []; 695702 const visText: (string | null)[] = []; 696703 const visWriter: number[] = []; 704+ const visK: number[] = []; 705+ const seqWriter: number[] = []; 706+ const seqK: number[] = []; 697707 const deletedBy = new Map<number, readonly number[]>(); 698708 const stack: number[] = []; 699709 const push = (code: number) => { Lines 722–734 at 232 (were 712–719 at 231)
713723 visText.push(texts.get(n) ?? null); 714724 visWriter.push(writers.get(n)!); 725+ visK.push(places.get(n)!); 716− if (complete) seq.push(n);
729+ seqWriter.push(writers.get(n)!); 730+ seqK.push(places.get(n)!); Lines 739–746 at 232 (were 724–729 at 231)
726741 visWriter: Int32Array.from(visWriter), 742+ visK: Int32Array.from(visK), 743+ ...(complete ? { seqWriter: Int32Array.from(seqWriter), seqK: Int32Array.from(seqK) } : {}), Lines 901–913 at 232 (were 884–896 at 231)
884901 buildLines(path: string): readonly VisibleLine[] { 885902 const graph = this.graph; 886903 // Texts and writers the packed layout already holds are not read again (abso Capacity). 887− const { vis, visText, visWriter } = this.#file(path);
904+ const { vis, visText, visWriter, visK } = this.#file(path); 888905 const lines: VisibleLine[] = new Array(vis.length); 889906 for (let i = 0; i < vis.length; i++) { 890907 const n = vis[i]!; 891908 const packed = visText?.[i]; 893− id: graph.lineIdOf(n),
910+ id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n), 894911 textChunks: () => graph.textChunks(n), 896913 return packed ?? graph.textOf(n); Lines 922–933 at 232 (were 905–916 at 231)
905922 lines(path: string): readonly VisibleLine[] { 906923 if (this.#linesCache?.path === path) return this.#linesCache.lines; 907924 const graph = this.graph; 908− const { vis, visText, visWriter } = this.#file(path);
925+ const { vis, visText, visWriter, visK } = this.#file(path); 909926 const lines: VisibleLine[] = new Array(vis.length); 910927 for (let i = 0; i < vis.length; i++) { 911928 const n = vis[i]!; 913− id: graph.lineIdOf(n),
930+ id: visWriter && visK ? lineId(graph.idOfSeq(visWriter[i]!), visK[i]!) : graph.lineIdOf(n), 914931 text: visText?.[i] ?? graph.textOf(n), 915932 atom: graph.idOfSeq(visWriter ? visWriter[i]! : graph.writerSeqOf(n)), Lines 942–962 at 232 (were 925–937 at 231)
925942 const graph = this.graph; 926943 const f = this.#file(path, true); 927944 const out: SeqLine[] = new Array(f.seq.length); 945+ // Ids and writers from the packed layout, and each text read only when asked (abso Capacity): callers walk a few 946+ // lines of a file's history, and reading every line's text was a row each on a stored graph. 947+ const { seqWriter, seqK } = f; 928948 for (let i = 0; i < f.seq.length; i++) { 929949 const n = f.seq[i]!; 930950 const by = f.deletedBy.get(i); 951+ const writer = seqWriter ? seqWriter[i]! : graph.writerSeqOf(n); 952+ let text: string | undefined; 932− id: graph.lineIdOf(n),
933− text: graph.textOf(n),
934− atom: graph.idOfSeq(graph.writerSeqOf(n)),
954+ id: seqWriter && seqK ? lineId(graph.idOfSeq(writer), seqK[i]!) : graph.lineIdOf(n), 956+ text ??= graph.textOf(n); 959+ atom: graph.idOfSeq(writer), 935960 deletedBy: by ? by.map((s) => graph.idOfSeq(s)) : NONE, 936961 visible: by === undefined, Lines 1078–1086 at 232 (were 1053–1058 at 231)
10531078 n += f.seq.byteLength + f.vis.byteLength; 10541079 if (f.visText) for (const text of f.visText) n += REFERENCE_BYTES + 2 * (text?.length ?? 0); 10551080 if (f.visWriter) n += 4 * f.visWriter.length; 1081+ if (f.visK) n += 4 * f.visK.length; 1082+ if (f.seqWriter) n += 4 * f.seqWriter.length; 1083+ if (f.seqK) n += 4 * f.seqK.length; 10561084 n += MAP_HEADER_BYTES + (MAP_ENTRY_BYTES + ARRAY_HEADER_BYTES) * f.deletedBy.size; 10571085 for (const deleters of f.deletedBy.values()) n += REFERENCE_BYTES * deleters.length; 10581086 if (f.seqIndex) n += MAP_HEADER_BYTES + MAP_ENTRY_BYTES * f.seqIndex.size;