mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
style: Simplify the cascade function in the custom_properties module.
This commit is contained in:
parent
c44826f1cc
commit
369c2f299e
1 changed files with 36 additions and 34 deletions
|
@ -329,41 +329,43 @@ pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedSpec
|
||||||
seen: &mut HashSet<&'a Name>,
|
seen: &mut HashSet<&'a Name>,
|
||||||
name: &'a Name,
|
name: &'a Name,
|
||||||
specified_value: &'a DeclaredValue<SpecifiedValue>) {
|
specified_value: &'a DeclaredValue<SpecifiedValue>) {
|
||||||
let was_not_already_present = seen.insert(name);
|
let was_already_present = !seen.insert(name);
|
||||||
if was_not_already_present {
|
if was_already_present {
|
||||||
let map = match *custom_properties {
|
return;
|
||||||
Some(ref mut map) => map,
|
}
|
||||||
None => {
|
|
||||||
*custom_properties = Some(match *inherited {
|
let map = match *custom_properties {
|
||||||
Some(ref inherited) => inherited.iter().map(|(key, inherited_value)| {
|
Some(ref mut map) => map,
|
||||||
(key, BorrowedSpecifiedValue {
|
None => {
|
||||||
css: &inherited_value.css,
|
*custom_properties = Some(match *inherited {
|
||||||
first_token_type: inherited_value.first_token_type,
|
Some(ref inherited) => inherited.iter().map(|(key, inherited_value)| {
|
||||||
last_token_type: inherited_value.last_token_type,
|
(key, BorrowedSpecifiedValue {
|
||||||
references: None
|
css: &inherited_value.css,
|
||||||
})
|
first_token_type: inherited_value.first_token_type,
|
||||||
}).collect(),
|
last_token_type: inherited_value.last_token_type,
|
||||||
None => HashMap::new(),
|
references: None
|
||||||
});
|
})
|
||||||
custom_properties.as_mut().unwrap()
|
}).collect(),
|
||||||
}
|
None => HashMap::new(),
|
||||||
};
|
});
|
||||||
match *specified_value {
|
custom_properties.as_mut().unwrap()
|
||||||
DeclaredValue::Value(ref specified_value) => {
|
|
||||||
map.insert(name, BorrowedSpecifiedValue {
|
|
||||||
css: &specified_value.css,
|
|
||||||
first_token_type: specified_value.first_token_type,
|
|
||||||
last_token_type: specified_value.last_token_type,
|
|
||||||
references: Some(&specified_value.references),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
|
||||||
DeclaredValue::Initial => {
|
|
||||||
map.remove(&name);
|
|
||||||
}
|
|
||||||
DeclaredValue::Unset | // Custom properties are inherited by default.
|
|
||||||
DeclaredValue::Inherit => {} // The inherited value is what we already have.
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
match *specified_value {
|
||||||
|
DeclaredValue::Value(ref specified_value) => {
|
||||||
|
map.insert(name, BorrowedSpecifiedValue {
|
||||||
|
css: &specified_value.css,
|
||||||
|
first_token_type: specified_value.first_token_type,
|
||||||
|
last_token_type: specified_value.last_token_type,
|
||||||
|
references: Some(&specified_value.references),
|
||||||
|
});
|
||||||
|
},
|
||||||
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
|
DeclaredValue::Initial => {
|
||||||
|
map.remove(&name);
|
||||||
|
}
|
||||||
|
DeclaredValue::Unset | // Custom properties are inherited by default.
|
||||||
|
DeclaredValue::Inherit => {} // The inherited value is what we already have.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue