diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-08-01 23:19:23 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2015-08-02 09:10:17 -0700 |
commit | 9bd8edea4ae18f037de3351e775623248012e16e (patch) | |
tree | 5b974f2dd70394c8e4aa8b45b6be495e0003ba1f | |
parent | 92cbb9368471d12f0d5492abd7e04b16df549366 (diff) | |
download | servo-9bd8edea4ae18f037de3351e775623248012e16e.tar.gz servo-9bd8edea4ae18f037de3351e775623248012e16e.zip |
script: Use `Arc::make_unique` instead of `Arc::get_mut` when updating
inline styles.
Transitions make the reasoning in the comment in the relevant sections
not true.
-rw-r--r-- | components/script/dom/element.rs | 21 | ||||
-rw-r--r-- | components/style/properties.mako.rs | 2 |
2 files changed, 11 insertions, 12 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 73643b7cf5b..5ead9ead378 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -660,7 +660,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { .iter() .position(|decl| decl.name() == property); if let Some(index) = index { - Arc::get_mut(&mut declarations.normal).unwrap().remove(index); + Arc::make_unique(&mut declarations.normal).remove(index); return; } @@ -668,7 +668,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { .iter() .position(|decl| decl.name() == property); if let Some(index) = index { - Arc::get_mut(&mut declarations.important).unwrap().remove(index); + Arc::make_unique(&mut declarations.important).remove(index); return; } } @@ -682,11 +682,10 @@ impl<'a> ElementHelpers<'a> for &'a Element { } else { &mut declarations.normal }; - // Element is the only owner of the Arc’s for its style attribute, - // except during selector matching. - // But selector matching does not run concurrently with script. - let existing_declarations = Arc::get_mut(existing_declarations).unwrap(); + // Usually, the reference count will be 1 here. But transitions could make it greater + // than that. + let existing_declarations = Arc::make_unique(existing_declarations); for declaration in existing_declarations.iter_mut() { if declaration.name() == property_decl.name() { *declaration = property_decl; @@ -717,11 +716,11 @@ impl<'a> ElementHelpers<'a> for &'a Element { } else { (&mut declarations.normal, &mut declarations.important) }; - // Element is the only owner of the Arc’s for its style attribute, - // except during selector matching. - // But selector matching does not run concurrently with script. - let from = Arc::get_mut(from).unwrap(); - let to = Arc::get_mut(to).unwrap(); + + // Usually, the reference counts of `from` and `to` will be 1 here. But transitions + // could make them greater than that. + let from = Arc::make_unique(from); + let to = Arc::make_unique(to); let mut new_from = Vec::new(); for declaration in from.drain(..) { if properties.contains(&declaration.name()) { diff --git a/components/style/properties.mako.rs b/components/style/properties.mako.rs index 5d15cd1bb0b..d17241e009f 100644 --- a/components/style/properties.mako.rs +++ b/components/style/properties.mako.rs @@ -5669,7 +5669,7 @@ impl<T: ToCss> DeclaredValue<T> { } } -#[derive(PartialEq)] +#[derive(PartialEq, Clone)] pub enum PropertyDeclaration { % for property in LONGHANDS: ${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>), |