pub struct StyleSharingCache<E: TElement> {
cache_typeless: AtomicRefMut<'static, [SharingCacheBase<StyleSharingCandidate<usize>>; 8]>,
marker: PhantomData<SendElement<E>>,
}Expand description
A set of LRU caches of the last few nodes seen, one per DOM depth, so that we can try to aggressively try to share their styles.
We key the candidates by DOM depth, because sharing requires an identical inheritance parent
(see test_candidate), which in practice means the candidates worth testing are the ones at the
target’s own depth.
Note that these caches only live for the duration of one traversal so storing nodes here temporarily is safe.
Fields§
§cache_typeless: AtomicRefMut<'static, [SharingCacheBase<StyleSharingCandidate<usize>>; 8]>The per-depth LRU caches, with the type cast away to allow persisting the allocation across traversals.
marker: PhantomData<SendElement<E>>Bind this structure to the lifetime of E, since that’s what we effectively store.
Implementations§
Source§impl<E: TElement> StyleSharingCache<E>
impl<E: TElement> StyleSharingCache<E>
fn cache_mut_at( &mut self, index: usize, ) -> &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,
inputs: &CascadeInputs,
target: E,
dom_depth: usize,
) -> Option<PrimaryStyle>
pub fn lookup_by_rules( &mut self, shared_context: &SharedStyleContext<'_>, inherited: &ComputedValues, inputs: &CascadeInputs, target: E, dom_depth: usize, ) -> 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§
Source§impl<E: TElement> Default for StyleSharingCache<E>
impl<E: TElement> Default for StyleSharingCache<E>
Source§impl<E: TElement> Drop for StyleSharingCache<E>
impl<E: TElement> Drop for StyleSharingCache<E>
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> UnsafeUnpin for StyleSharingCache<E>
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