Skip to content

Truly independent web browser

LibWeb: Walk custom property reads rather than collecting them

Andreas Klingf2ae528fcd1e
diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
index a09b42b4697..7b25468426e 100644
--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
@@ -418,14 +418,14 @@ pub(super) fn append_named_custom_property_reads(value: &StyleValueData, names:
let Some(reads) = named_custom_property_reads(value) else {
return false;
};
- names.extend(reads.into_iter().map(Arc::from));
+ names.extend(reads.map(Arc::from));
true
}
/// The custom properties a written value reads by name, or `None` when it may read others: an
/// `if()` condition, a custom function or an attribute's value can read any, and `inherit()` reads
/// what the parent holds, which holds more than it hands down.
-fn named_custom_property_reads(value: &StyleValueData) -> Option<Vec<&[u16]>> {
+fn named_custom_property_reads(value: &StyleValueData) -> Option<impl Iterator<Item = &[u16]>> {
let value = substituted_tokens(value);
if let StyleValueData::Unresolved(unresolved) = value
&& (unresolved.presence().attr
@@ -436,9 +436,9 @@ fn named_custom_property_reads(value: &StyleValueData) -> Option<Vec<&[u16]>> {
return None;
}
let Some((references, all_references_visible)) = custom_property_references(value) else {
- return Some(Vec::new());
+ return Some(None.into_iter().flatten());
};
- all_references_visible.then_some(references)
+ all_references_visible.then(|| Some(references).into_iter().flatten())
}
/// Whether a written value holds a function that substitutes anything.
@@ -505,7 +505,7 @@ fn nodes_on_a_cycle(edges: &[Vec<usize>]) -> Vec<bool> {
/// Whether a written value may read one of the custom properties `moved` holds.
pub(super) fn value_reads_any_custom_property_of(value: &StyleValueData, moved: impl Fn(&[u16]) -> bool) -> bool {
- named_custom_property_reads(value).is_none_or(|names| names.into_iter().any(moved))
+ named_custom_property_reads(value).is_none_or(|mut names| names.any(moved))
}
pub(super) fn sorted_custom_property_names(mut names: Vec<Arc<[u16]>>) -> CustomPropertyNames {
@@ -1007,7 +1007,12 @@ impl RetainedState {
.filter(|(declared, _)| declared.operator() == CascadeOperator::Declared)
.filter_map(|(declared, value)| {
let name = self.declared_custom_property_name(declared.name)?;
- Some((name, declared, value, named_custom_property_reads(value.data())))
+ Some((
+ name,
+ declared,
+ value,
+ named_custom_property_reads(value.data()).map(Iterator::collect),
+ ))
})
.filter(|(name, _, _, _)| !moved.contains(name.to_utf16().as_ref()))
.collect();
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs
index 1af046c5acd..b2d9cd2c1d2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs
@@ -455,7 +455,6 @@ impl RetainedState {
.filter(|(_, all_visible)| *all_visible)
.and_then(|(names, _)| {
names
- .iter()
.map(|name| {
stores.own.map_or(Some(0), |store| {
store.resolved_value_identity(&ak::Utf16FlyString::from_utf16(name))
diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rs
index 94c5cdf5a3e..14a36c17bea 100644
--- a/Libraries/LibWeb/Rust/src/css/style_value.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs
@@ -201,14 +201,11 @@ fn scan_custom_property_references<'a>(
all_references_visible
}
-pub(crate) fn custom_property_references(value: &StyleValueData) -> Option<(Vec<&[u16]>, bool)> {
+pub(crate) fn custom_property_references(value: &StyleValueData) -> Option<(impl Iterator<Item = &[u16]>, bool)> {
let StyleValueData::Unresolved(unresolved_payload) = value else {
return None;
};
- Some((
- unresolved_payload.references().collect(),
- unresolved_payload.references_visible(),
- ))
+ Some((unresolved_payload.references(), unresolved_payload.references_visible()))
}
/// Visits the Typed OM reification of an unresolved style value. Event 0 appends a text segment,
@@ -299,7 +296,7 @@ mod unresolved_component_tests {
fn reference_names(value: &StyleValueData) -> (Vec<String>, bool) {
let (names, all_visible) = custom_property_references(value).unwrap();
(
- names.iter().map(|name| String::from_utf16(name).unwrap()).collect(),
+ names.map(|name| String::from_utf16(name).unwrap()).collect(),
all_visible,
)
}