Skip to content

Truly independent web browser

LibWeb: Separate custom property interval cache lookup and insertion

Callum Law9785a1c11d4a
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 03be3a965bc..0912903f39f 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -9129,10 +9129,15 @@ pub(crate) fn resolve_published_animation_declarations(
let name_id = interval.custom_name_id;
let important = custom_properties.is_important(name_id);
let name = custom_properties.units(name_id);
- let (interval_values, values_are_retained) = effect.resolve_custom_property_interval_values(
- interval.declaration_indices(),
- registry.name_has_interpolable_syntax(name),
- || {
+ let (retained_interval_values, can_retain_interval_values) = effect
+ .retained_custom_property_interval_values(
+ interval.declaration_indices(),
+ registry.name_has_interpolable_syntax(name),
+ );
+ let has_retained_values = retained_interval_values.is_some();
+ let interval_values = match retained_interval_values {
+ Some(values) => values,
+ None => {
interval.interval_span.map(|lookup| {
let declaration = effect.custom_declaration_at(lookup.declaration_index);
match &declaration.value {
@@ -9145,11 +9150,17 @@ pub(crate) fn resolve_published_animation_declarations(
PublishedValue::Declared(value) => value.clone_retained(),
}
})
- },
- );
+ }
+ };
// SAFETY: The sample keeps the name alive while it is retained for the lookup.
let interned_name = unsafe { ak::Utf16FlyString::from_raw_borrowed(custom_properties.name(name_id).raw()) };
let custom_is_inherited = registry.name_inherits(&interned_name);
+ if can_retain_interval_values && !has_retained_values {
+ effect.update_retained_custom_property_interval_values(
+ interval.declaration_indices(),
+ interval_values.clone(),
+ );
+ }
for (lookup, value) in interval.interval_span.into_iter().zip(interval_values) {
let declaration = effect.custom_declaration_at(lookup.declaration_index);
declarations.push(AnimationDeclaration {
@@ -9164,7 +9175,7 @@ pub(crate) fn resolve_published_animation_declarations(
is_transition,
});
}
- custom_properties.has_uncached_interval_values |= !values_are_retained;
+ custom_properties.has_uncached_interval_values |= !can_retain_interval_values;
custom_properties.intervals.push(interval);
}
effects.push(FfiAnimationEffect {
diff --git a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
index f2fc9817056..6c18a6153fd 100644
--- a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
@@ -420,20 +420,18 @@ impl PublishedEffect {
&self.keyframes.custom_declarations[index]
}
- /// Resolve interval values afresh for interpolable syntaxes or neutral keyframes; retain them otherwise.
- /// Also report whether the values are retained across samples.
- pub(crate) fn resolve_custom_property_interval_values(
+ /// Look up retained interval values, also reporting whether the interval retains its values across samples.
+ pub(crate) fn retained_custom_property_interval_values(
&self,
declaration_indices: [usize; 2],
has_interpolable_syntax: bool,
- resolve_values: impl FnOnce() -> [RetainedStyleValueData; 2],
- ) -> ([RetainedStyleValueData; 2], bool) {
+ ) -> (Option<[RetainedStyleValueData; 2]>, bool) {
let has_neutral_endpoint = declaration_indices
.iter()
.any(|&index| matches!(self.custom_declaration_at(index).value, PublishedValue::ElementValue));
if has_interpolable_syntax || has_neutral_endpoint {
- return (resolve_values(), false);
+ return (None, false);
}
// AD-HOC: Match Chromium's retention of substituted interval values for discrete interpolations
@@ -445,11 +443,25 @@ impl PublishedEffect {
.expect("an effect interpolating custom properties keeps their interval values")
.lock()
.unwrap()
- .entry(declaration_indices)
- .or_insert_with(resolve_values)
- .clone();
+ .get(&declaration_indices)
+ .cloned();
(values, true)
}
+
+ /// Retain freshly resolved values for an interval.
+ pub(crate) fn update_retained_custom_property_interval_values(
+ &self,
+ declaration_indices: [usize; 2],
+ values: [RetainedStyleValueData; 2],
+ ) {
+ self.custom_property_interval_values
+ .as_ref()
+ .expect("an effect interpolating custom properties keeps their interval values")
+ .lock()
+ .unwrap()
+ .entry(declaration_indices)
+ .or_insert(values);
+ }
}
/// The flat buffers one animation list's descriptions travel in.