pub struct BufferDiff { /* private fields */ }Expand description
The diff between two buffers.
Contains the list of (x, y) positions where cells differ.
Implementations§
Source§impl BufferDiff
impl BufferDiff
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a diff with pre-allocated capacity.
Sourcepub fn full(width: u16, height: u16) -> Self
pub fn full(width: u16, height: u16) -> Self
Create a diff that marks every cell as changed.
Useful for full-screen redraws where the previous buffer is unknown (e.g., after resize or initial present).
Sourcepub fn compute(old: &Buffer, new: &Buffer) -> Self
pub fn compute(old: &Buffer, new: &Buffer) -> Self
Compute the diff between two buffers.
Uses row-major scan for cache efficiency. Both buffers must have the same dimensions.
§Optimizations
- Row-skip fast path: unchanged rows are detected via slice equality and skipped entirely. For typical UI updates where most rows are static, this eliminates the majority of per-cell work.
- Blockwise row scan: rows with sparse edits are scanned in coarse blocks, skipping unchanged blocks and only diving into the blocks that differ.
- Direct slice iteration: row slices are computed once per row
instead of calling
get_unchecked(x, y)per cell, eliminating repeatedy * width + xindex arithmetic. - Branchless cell comparison:
bits_equses bitwise AND to avoid branch mispredictions in the inner loop.
§Panics
Debug-asserts that both buffers have identical dimensions.
Sourcepub fn compute_into(&mut self, old: &Buffer, new: &Buffer)
pub fn compute_into(&mut self, old: &Buffer, new: &Buffer)
Compute the diff into an existing buffer to reuse allocation.
Sourcepub fn compute_dirty(old: &Buffer, new: &Buffer) -> Self
pub fn compute_dirty(old: &Buffer, new: &Buffer) -> Self
Compute the diff between two buffers using dirty-row hints.
Only rows marked dirty in new are compared cell-by-cell.
Clean rows are skipped entirely (O(1) per clean row).
This is sound provided the dirty tracking invariant holds:
for all y, if any cell in row y changed, then new.is_row_dirty(y).
Falls back to full comparison for rows marked dirty, so false positives (marking a row dirty when it didn’t actually change) are safe — they only cost the per-cell scan for that row.
Sourcepub fn compute_dirty_into(&mut self, old: &Buffer, new: &Buffer)
pub fn compute_dirty_into(&mut self, old: &Buffer, new: &Buffer)
Compute the dirty-row diff into an existing buffer to reuse allocation.
Sourcepub fn compute_certified_into(
&mut self,
old: &Buffer,
new: &Buffer,
hint: DiffSkipHint,
)
pub fn compute_certified_into( &mut self, old: &Buffer, new: &Buffer, hint: DiffSkipHint, )
Compute the diff with a certificate-based skip hint.
The caller (typically the runtime loop) evaluates a render certificate
and passes the result as a DiffSkipHint. This method shortcuts the
diff computation when the certificate allows it:
FullDiff: performs the standard dirty-diff computation.SkipDiff: clears changes (no work to present). The caller must ensure that old and new buffers are identical when issuing this hint.NarrowToRows(rows): only diffs the specified rows, skipping all others even if marked dirty. Useful when the certificate identifies exactly which rows changed.
§Safety invariant
Issuing SkipDiff when buffers differ produces stale frames.
The certificate evaluator must guarantee correctness — this method
trusts the hint without verification.
§Tracing
Emits a tracing event when a skip or narrow is applied, including the hint type and resulting change count for evidence logging.
Sourcepub fn fill_full(&mut self, width: u16, height: u16)
pub fn fill_full(&mut self, width: u16, height: u16)
Populate the diff with all cells (full redraw) reusing existing capacity.
Sourcepub fn last_tile_stats(&self) -> Option<TileDiffStats>
pub fn last_tile_stats(&self) -> Option<TileDiffStats>
Access the last tile diagnostics from a dirty diff pass.
Sourcepub fn tile_config_mut(&mut self) -> &mut TileDiffConfig
pub fn tile_config_mut(&mut self) -> &mut TileDiffConfig
Mutably access tile diff configuration.
Sourcepub fn runs(&self) -> Vec<ChangeRun>
pub fn runs(&self) -> Vec<ChangeRun>
Convert point changes into contiguous runs.
Consecutive x positions on the same row are coalesced into a single run. This enables efficient cursor positioning in the presenter.
Trait Implementations§
Source§impl Clone for BufferDiff
impl Clone for BufferDiff
Source§fn clone(&self) -> BufferDiff
fn clone(&self) -> BufferDiff
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more