Auto merge of #6896 - pcwalton:fix-particles-crash, r=SimonSapin

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.

r? @SimonSapin

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6896)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-08-02 10:10:39 -06:00
commit 0c6e271cd3
2 changed files with 11 additions and 12 deletions

View file

@ -660,7 +660,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
.iter() .iter()
.position(|decl| decl.name() == property); .position(|decl| decl.name() == property);
if let Some(index) = index { if let Some(index) = index {
Arc::get_mut(&mut declarations.normal).unwrap().remove(index); Arc::make_unique(&mut declarations.normal).remove(index);
return; return;
} }
@ -668,7 +668,7 @@ impl<'a> ElementHelpers<'a> for &'a Element {
.iter() .iter()
.position(|decl| decl.name() == property); .position(|decl| decl.name() == property);
if let Some(index) = index { if let Some(index) = index {
Arc::get_mut(&mut declarations.important).unwrap().remove(index); Arc::make_unique(&mut declarations.important).remove(index);
return; return;
} }
} }
@ -682,11 +682,10 @@ impl<'a> ElementHelpers<'a> for &'a Element {
} else { } else {
&mut declarations.normal &mut declarations.normal
}; };
// Element is the only owner of the Arcs 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() { for declaration in existing_declarations.iter_mut() {
if declaration.name() == property_decl.name() { if declaration.name() == property_decl.name() {
*declaration = property_decl; *declaration = property_decl;
@ -717,11 +716,11 @@ impl<'a> ElementHelpers<'a> for &'a Element {
} else { } else {
(&mut declarations.normal, &mut declarations.important) (&mut declarations.normal, &mut declarations.important)
}; };
// Element is the only owner of the Arcs for its style attribute,
// except during selector matching. // Usually, the reference counts of `from` and `to` will be 1 here. But transitions
// But selector matching does not run concurrently with script. // could make them greater than that.
let from = Arc::get_mut(from).unwrap(); let from = Arc::make_unique(from);
let to = Arc::get_mut(to).unwrap(); let to = Arc::make_unique(to);
let mut new_from = Vec::new(); let mut new_from = Vec::new();
for declaration in from.drain(..) { for declaration in from.drain(..) {
if properties.contains(&declaration.name()) { if properties.contains(&declaration.name()) {

View file

@ -5669,7 +5669,7 @@ impl<T: ToCss> DeclaredValue<T> {
} }
} }
#[derive(PartialEq)] #[derive(PartialEq, Clone)]
pub enum PropertyDeclaration { pub enum PropertyDeclaration {
% for property in LONGHANDS: % for property in LONGHANDS:
${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>), ${property.camel_case}(DeclaredValue<longhands::${property.ident}::SpecifiedValue>),