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
impl InheritedValues
pub const fn new() -> Self
pub const fn len(&self) -> usize
pub const fn is_empty(&self) -> bool
Sourcepub fn bucket_count(&self) -> usize
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.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Total (node, property) pairs — what the old per-node vecs would have stored one entry each for.
pub fn grow_to(&mut self, node_count: usize)
Sourcepub fn clear_values(&mut self)
pub fn clear_values(&mut self)
Drop every value, keeping the sizing. Called at the head of a cascade.
Sourcepub fn get(
&self,
node: usize,
prop_type: CssPropertyType,
) -> Option<&CssPropertyWithOrigin>
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.
Sourcepub fn values_for(
&self,
node: usize,
) -> Vec<(CssPropertyType, CssPropertyWithOrigin)>
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.
Sourcepub fn values_for_opt(
&self,
node: usize,
) -> Option<Vec<(CssPropertyType, CssPropertyWithOrigin)>>
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.
Sourcepub fn set_node(
&mut self,
node: usize,
entries: &[(CssPropertyType, CssPropertyWithOrigin)],
)
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.
Sourcepub fn append(&mut self, other: &mut Self)
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.
Sourcepub fn heap_bytes(&self) -> usize
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
impl Clone for InheritedValues
Source§fn clone(&self) -> InheritedValues
fn clone(&self) -> InheritedValues
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more