Skip to main content

BlockCache

Struct BlockCache 

Source
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.

Trait Implementations§

Source§

impl Default for BlockCache

Source§

fn default() -> BlockCache

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.