Skip to main content

cached_or_build

Function cached_or_build 

Source
pub fn cached_or_build<T, F: FnOnce() -> Arc<T>>(
    slot: &mut Option<(u64, Arc<T>)>,
    current_version: u64,
    build: F,
) -> Arc<T> ⓘ
Expand description

Perf plan B.4: cache-or-build helper for the sub-state Arc memoisation in build_render_state. Returns the cached Arc when current_version matches the version stored in slot; otherwise calls build, stores the result, and returns it.

Inlined into a single helper so each cached sub-state is one line at the call site instead of the same if let Some((v, arc)) = ... { ... } else { ... } pattern repeated five times.