Skip to main content

StyleSharingCache

Struct StyleSharingCache 

Source
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>

Source

fn cache_mut_at( &mut self, index: usize, ) -> &mut SharingCacheBase<StyleSharingCandidate<E>>

Source

pub fn new() -> Self

Create a new style sharing candidate cache.

Source

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.

Source

pub fn clear(&mut self)

Clear the style sharing candidate cache (all depths).

Source

fn share_style_if_possible( &mut self, shared_context: &SharedStyleContext<'_>, bloom_filter: &StyleBloom<E>, selector_caches: &mut SelectorCaches, target: &mut StyleSharingTarget<E>, ) -> Option<ResolvedElementStyles>

Attempts to share a style with another node.

Source

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>

Source

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>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<E: TElement> Drop for StyleSharingCache<E>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> MaybeBoxed<Box<T>> for T

Source§

fn maybe_boxed(self) -> Box<T>

Convert
Source§

impl<T> MaybeBoxed<T> for T

Source§

fn maybe_boxed(self) -> T

Convert
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,