pub struct ComputeCache { /* private fields */ }Expand description
An opt-in bounded cache for ComputedStyle results, keyed by an opaque
signature that captures (node identity, ancestor-chain signature, media
context, stylesheet generation).
See the module docs for the correctness invariants and the
eviction policy. Two computes with the same signature yield the same
ComputedStyle, so a hit short-circuits the cascade. The cache is an
access-order LRU: both a get hit and an insert of an existing key
promote that key to most-recently-used, and the least-recently-used entry is
evicted when the cache is full.
get takes &mut self for two reasons: a stylesheet generation mismatch
(detected on every access) clears the cache in place — see
Self::check_generation — and a hit promotes the key to the back of the
eviction order. Both get and insert are O(capacity) because promotion
scans the order deque.
Implementations§
Source§impl ComputeCache
impl ComputeCache
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Build a cache with the given hard capacity. capacity == 0 disables
storage: get always returns None and insert is a no-op.
Sourcepub fn get(&mut self, sig: u64, current_gen: u64) -> Option<ComputedStyle>
pub fn get(&mut self, sig: u64, current_gen: u64) -> Option<ComputedStyle>
Look up a cached result by signature. Returns an owned
ComputedStyle clone on a hit (cheap — a post-resolution
ComputedStyle holds no heap Color::Var).
A hit promotes sig to the back of the eviction order
(most-recently-used), so frequently accessed entries survive longer.
This is the access-order LRU promotion. The scan over the order deque
makes get O(capacity); acceptable for a small bounded cache. A miss
does NOT mutate the order.
&mut self because check_generation may
clear, and a hit promotes.
Sourcepub fn insert(&mut self, sig: u64, value: ComputedStyle, current_gen: u64)
pub fn insert(&mut self, sig: u64, value: ComputedStyle, current_gen: u64)
Insert a computed result under sig. If the key already exists, update
its value and move it to the back of the eviction order
(most-recently-used) — an access-order LRU promotion. If at capacity and
the key is new, evict the least-recently-used entry (front of the order).
A no-op when capacity is 0. O(capacity) due to the promotion scan.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ComputeCache
impl RefUnwindSafe for ComputeCache
impl Send for ComputeCache
impl Sync for ComputeCache
impl Unpin for ComputeCache
impl UnsafeUnpin for ComputeCache
impl UnwindSafe for ComputeCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more