Skip to main content

InheritedValues

Struct InheritedValues 

Source
pub struct InheritedValues { /* private fields */ }
Expand description

The slow path’s inherited-value store, TRANSPOSED: one copy of each distinct value plus the nodes that resolve to it.

The per-node shape (Vec<Vec<(CssPropertyType, CssPropertyWithOrigin)>>) paid for the VALUE once per node, and CssProperty is a 136-byte enum held inline. Inherited values are shared down a subtree by definition, so that is the worst possible layout for them: on the 50k-node XHTML bench the store held 53 476 entries carrying just EIGHT distinct values — cursor alone was 29 391 entries of one value, re-paid in every descendant of the node that set it.

Transposed, the same content is 215 KB instead of 8.1 MB (38x). The lookup stays cheap because the bucket count is tiny: a linear scan over ~6 property types beats hashing, and the node list is sorted (nodes are cascaded in increasing index order, so it is built by push) for a binary search.

INVARIANT: every bucket’s prop_type.is_inheritable() is true — this store is only ever written through CssPropertyCache::store_if_changed, which filters. Non-inherited properties live in cascaded_props / css_props / the compact cache.

Implementations§

Source§

impl InheritedValues

Source

pub const fn new() -> Self

Source

pub const fn len(&self) -> usize

Source

pub const fn is_empty(&self) -> bool

Source

pub fn bucket_count(&self) -> usize

Number of distinct (type, value) buckets — the figure the scan cost is linear in. Exposed for the memory/coverage tests.

Source

pub fn entry_count(&self) -> usize

Total (node, property) pairs — what the old per-node vecs would have stored one entry each for.

Source

pub fn grow_to(&mut self, node_count: usize)

Source

pub fn clear_values(&mut self)

Drop every value, keeping the sizing. Called at the head of a cascade.

Source

pub fn get( &self, node: usize, prop_type: CssPropertyType, ) -> Option<&CssPropertyWithOrigin>

The resolved value of prop_type for node, if any.

Linear over buckets (a handful) then binary over the node list.

Source

pub fn values_for( &self, node: usize, ) -> Vec<(CssPropertyType, CssPropertyWithOrigin)>

Every (type, value) this node resolved to, ascending by type — the shape the per-node Vec used to hand out.

Source

pub fn values_for_opt( &self, node: usize, ) -> Option<Vec<(CssPropertyType, CssPropertyWithOrigin)>>

values_for, as an Option that is None when the node resolved to nothing — the shape Vec<Vec<_>>::get had, so if let Some(..) call sites keep their structure.

None iff node is outside the store; a node that exists but resolved no inherited properties yields Some(vec![]).

This used to key off emptiness ((!v.is_empty()).then_some(v)), which made “this node has nothing” and “there is no such node” indistinguishable. That was harmless while every node held a value, but the store now keeps only properties a reader can actually reach, so a plain <div> with no inherited CSS legitimately has none - and the caller could no longer tell that from an out-of-range index.

Source

pub fn set_node( &mut self, node: usize, entries: &[(CssPropertyType, CssPropertyWithOrigin)], )

Record entries as node’s resolved set.

Nodes are cascaded in ascending index order, so each nodes list is built by push and stays sorted without an insert.

Source

pub fn append(&mut self, other: &mut Self)

Absorb another store whose nodes sit after this one’s (subtree composition), shifting its node indices by this store’s node count.

Source

pub fn heap_bytes(&self) -> usize

Approximate retained heap bytes: one value per bucket plus the node ids.

Trait Implementations§

Source§

impl Clone for InheritedValues

Source§

fn clone(&self) -> InheritedValues

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for InheritedValues

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for InheritedValues

Source§

fn default() -> InheritedValues

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

impl PartialEq for InheritedValues

Source§

fn eq(&self, other: &InheritedValues) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for InheritedValues

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.