pub struct BlockCache { /* private fields */ }Expand description
A persistent, content-keyed cache of the rows each top-level block renders
to — the VisualMap analogue of the GUI’s ShapedLine cache, one level
down. Held by a crate::Doc and threaded into build_cached, it is what
makes a rebuild after a keystroke cost “re-render the edited block + shift
the rest” instead of re-rendering the whole document.
A top-level block’s rows are a pure function of its source bytes and the wrap
width, so an unchanged block’s rows are cloned and their source offsets
shifted by the edit’s byte delta rather than rebuilt glyph by glyph. Two
things make that purity hold: at the top level the render prefix is always
empty (nesting prefixes — a quote gutter, a list indent — exist only inside
a top-level block, within its cached unit), and a block’s output never reads
the incoming last_off (it writes last_off from its own content before any
nested separator reads it). So the only thing that differs between two
positions of an unchanged block is a uniform offset shift. Keyed by a fast
hash of the block’s bytes with the bytes kept for a verify-on-hit — exactly
the shape cache’s weak-hash-then-compare, so a collision costs a re-render,
never a wrong row.
Tables are never cached (a block that emits any table row is always rebuilt):
their rows are cross-referenced from the map’s tables side-table by row
index, which a blind offset-shift wouldn’t fix up, and they are rare enough
that the simplicity beats the reuse.