Struct style::sharing::StyleSharingCache
source · pub struct StyleSharingCache<E: TElement> {
cache_typeless: AtomicRefMut<'static, SharingCacheBase<FakeCandidate>>,
marker: PhantomData<SendElement<E>>,
dom_depth: usize,
}
Expand description
An LRU cache of the last few nodes seen, so that we can aggressively try to reuse their styles.
Note that this cache is flushed every time we steal work from the queue, so storing nodes here temporarily is safe.
Fields§
§cache_typeless: AtomicRefMut<'static, SharingCacheBase<FakeCandidate>>
The LRU cache, with the type cast away to allow persisting the allocation.
marker: PhantomData<SendElement<E>>
Bind this structure to the lifetime of E, since that’s what we effectively store.
dom_depth: usize
The DOM depth we’re currently at. This is used as an optimization to clear the cache when we change depths, since we know at that point nothing in the cache will match.
Implementations§
source§impl<E: TElement> StyleSharingCache<E>
impl<E: TElement> StyleSharingCache<E>
fn cache(&self) -> &SharingCacheBase<StyleSharingCandidate<E>>
fn cache_mut(&mut self) -> &mut SharingCacheBase<StyleSharingCandidate<E>>
sourcepub fn insert_if_possible(
&mut self,
element: &E,
style: &PrimaryStyle,
validation_data_holder: Option<&mut StyleSharingTarget<E>>,
dom_depth: usize,
shared_context: &SharedStyleContext<'_>,
)
pub fn insert_if_possible( &mut self, element: &E, style: &PrimaryStyle, validation_data_holder: Option<&mut StyleSharingTarget<E>>, dom_depth: usize, shared_context: &SharedStyleContext<'_>, )
Tries to insert an element in the style sharing cache.
Fails if we know it should never be in the cache.
NB: We pass a source for the validation data, rather than the data itself, to avoid memmoving at each function call. See rust issue #42763.
Attempts to share a style with another node.
fn test_candidate( target: &mut StyleSharingTarget<E>, candidate: &mut StyleSharingCandidate<E>, shared: &SharedStyleContext<'_>, bloom: &StyleBloom<E>, selector_caches: &mut SelectorCaches, shared_context: &SharedStyleContext<'_>, ) -> Option<ResolvedElementStyles>
sourcepub fn lookup_by_rules(
&mut self,
shared_context: &SharedStyleContext<'_>,
inherited: &ComputedValues,
rules: &StrongRuleNode,
visited_rules: Option<&StrongRuleNode>,
target: E,
) -> Option<PrimaryStyle>
pub fn lookup_by_rules( &mut self, shared_context: &SharedStyleContext<'_>, inherited: &ComputedValues, rules: &StrongRuleNode, visited_rules: Option<&StrongRuleNode>, target: E, ) -> Option<PrimaryStyle>
Attempts to find an element in the cache with the given primary rule node and parent.
FIXME(emilio): re-measure this optimization, and remove if it’s not very useful… It’s probably not worth the complexity / obscure bugs.
Trait Implementations§
Auto Trait Implementations§
impl<E> Freeze for StyleSharingCache<E>
impl<E> !RefUnwindSafe for StyleSharingCache<E>
impl<E> Send for StyleSharingCache<E>
impl<E> Sync for StyleSharingCache<E>where
E: Sync,
impl<E> Unpin for StyleSharingCache<E>where
E: Unpin,
impl<E> !UnwindSafe for StyleSharingCache<E>
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