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>

source

fn cache(&self) -> &SharingCacheBase<StyleSharingCandidate<E>>

source

fn cache_mut(&mut self) -> &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.

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, 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§

source§

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

source§

fn drop(&mut self)

Executes the destructor for this type. 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> !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,

source§

impl<T> MaybeSendSync for T