Skip to main content

BufferDiff

Struct BufferDiff 

Source
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

Source

pub fn new() -> Self

Create an empty diff.

Source

pub fn with_capacity(capacity: usize) -> Self

Create a diff with pre-allocated capacity.

Source

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

Source

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 repeated y * width + x index arithmetic.
  • Branchless cell comparison: bits_eq uses bitwise AND to avoid branch mispredictions in the inner loop.
§Panics

Debug-asserts that both buffers have identical dimensions.

Source

pub fn compute_into(&mut self, old: &Buffer, new: &Buffer)

Compute the diff into an existing buffer to reuse allocation.

Source

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.

Source

pub fn compute_dirty_into(&mut self, old: &Buffer, new: &Buffer)

Compute the dirty-row diff into an existing buffer to reuse allocation.

Source

pub fn len(&self) -> usize

Number of changed cells.

Source

pub fn is_empty(&self) -> bool

Check if no cells changed.

Source

pub fn changes(&self) -> &[(u16, u16)]

Get the list of changed positions.

Source

pub fn last_tile_stats(&self) -> Option<TileDiffStats>

Access the last tile diagnostics from a dirty diff pass.

Source

pub fn tile_config_mut(&mut self) -> &mut TileDiffConfig

Mutably access tile diff configuration.

Source

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.

Source

pub fn runs_into(&self, out: &mut Vec<ChangeRun>)

Like runs() but writes into a caller-provided buffer, avoiding per-frame allocation when the buffer is reused across frames.

Source

pub fn iter(&self) -> impl Iterator<Item = (u16, u16)> + '_

Iterate over changed positions.

Source

pub fn clear(&mut self)

Clear the diff, removing all recorded changes.

Trait Implementations§

Source§

impl Clone for BufferDiff

Source§

fn clone(&self) -> BufferDiff

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BufferDiff

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferDiff

Source§

fn default() -> BufferDiff

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.