_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)
}
}
@@ -36,7 +36,8 @@ extension _BString {
// full grapheme breaking state of the ingester at the start of the insertion.
// (We'll use it to resync grapheme breaks in the parts that follow the insertion.)
var (ingester, _, path) = ingester(forInserting: other, at: index, allowForwardPeek: false)
let r = rope[path.rope].insert(from: &ingester, at: path.chunk)
let i = path.chunk
let r = rope.update(at: &path.rope) { $0.insert(from: &ingester, at: i) }
switch r {
case let .inline(r):
assert(ingester.isAtEnd)