_Rope: Add a leaf node reference to indices. Implement explicit index invalidation

This commit is contained in:
Karoy Lorentey committed 2023-03-20 13:12:09 -07:00
1 parent 8f48c3ae37
commit 3cc5a3888a
21 files changed
+671 -281

No files matched your search

@@ -58,12 +58,11 @@ extension _BString {
to i: Index,
preferEnd: Bool
) -> (path: Path, chunk: Chunk) {
let r = rope.find(at: i._utf8Offset, in: UTF8Metric(), preferEnd: preferEnd)
return r.node!.readLeaf {
let slot = r.index[height: 0]
let index = $0.children[slot].value.index(at: r.remaining, utf16Delta: i._utf16Delta)
return (Path(r.index, index), $0.children[slot].value)
}
let (ropeIndex, remaining) = rope.find(
at: i._utf8Offset, in: UTF8Metric(), preferEnd: preferEnd)
let chunk = rope[ropeIndex]
let chunkIndex = chunk.index(at: remaining, utf16Delta: i._utf16Delta)
return (Path(ropeIndex, chunkIndex), chunk)
}
}