pub struct StyleCache { /* private fields */ }Expand description
Cache for style resolution results.
This cache stores resolved styles keyed by their inputs, allowing views with identical styling to share the same resolved style object.
Unlike a simple hash cache, this validates parent inherited properties on lookup to ensure correctness (matching Chromium’s MatchedPropertiesCache).
Implementations§
Source§impl StyleCache
impl StyleCache
Sourcepub fn get(
&mut self,
key: &StyleCacheKey,
parent_style: &Rc<Style>,
) -> Option<(Rc<Style>, bool)>
pub fn get( &mut self, key: &StyleCacheKey, parent_style: &Rc<Style>, ) -> Option<(Rc<Style>, bool)>
Look up a cached style resolution result.
This performs Chromium-style validation: even if the hash matches, we verify that the parent’s inherited properties are equal.
Uses a two-tier lookup for performance:
- Fast path: pointer comparison (O(1)) - hits when same Rc instance
- Slow path: inherited_equal() comparison - for equivalent but different Rc instances
Returns Some((style, classes_applied)) if found, None otherwise.
Sourcepub fn insert(
&mut self,
key: StyleCacheKey,
computed_style: Style,
parent_style: &Rc<Style>,
classes_applied: bool,
)
pub fn insert( &mut self, key: StyleCacheKey, computed_style: Style, parent_style: &Rc<Style>, classes_applied: bool, )
Insert a style resolution result into the cache.
We store the parent’s inherited style so we can validate on lookup. The parent Rc pointer is stored for fast pointer-based lookups.
Sourcepub fn is_cacheable(style: &Style) -> bool
pub fn is_cacheable(style: &Style) -> bool
Check if a style is cacheable.
Some styles cannot be safely cached because their computed value depends on factors not captured in the cache key.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StyleCache
impl !RefUnwindSafe for StyleCache
impl !Send for StyleCache
impl !Sync for StyleCache
impl Unpin for StyleCache
impl !UnwindSafe for StyleCache
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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