style: Fix C++ side of <length-percentage> values.

Differential Revision: https://phabricator.services.mozilla.com/D63398
This commit is contained in:
Emilio Cobos Álvarez 2020-02-21 00:46:50 +00:00
parent 7e8dbd0896
commit 280402b2a1
3 changed files with 10 additions and 10 deletions

View file

@ -552,6 +552,7 @@ impl<'de> Deserialize<'de> for LengthPercentage {
/// The leaves of a `<length-percentage>` calc expression. /// The leaves of a `<length-percentage>` calc expression.
#[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToCss, ToResolvedValue)] #[derive(Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToAnimatedZero, ToCss, ToResolvedValue)]
#[allow(missing_docs)] #[allow(missing_docs)]
#[repr(u8)]
pub enum CalcLengthPercentageLeaf { pub enum CalcLengthPercentageLeaf {
Length(Length), Length(Length),
Percentage(Percentage), Percentage(Percentage),

View file

@ -54,9 +54,9 @@ pub enum GenericCalcNode<L> {
Leaf(L), Leaf(L),
/// A sum node, representing `a + b + c` where a, b, and c are the /// A sum node, representing `a + b + c` where a, b, and c are the
/// arguments. /// arguments.
Sum(Box<[GenericCalcNode<L>]>), Sum(crate::OwnedSlice<GenericCalcNode<L>>),
/// A `min` or `max` function. /// A `min` or `max` function.
MinMax(Box<[GenericCalcNode<L>]>, MinMaxOp), MinMax(crate::OwnedSlice<GenericCalcNode<L>>, MinMaxOp),
/// A `clamp()` function. /// A `clamp()` function.
Clamp { Clamp {
/// The minimum value. /// The minimum value.
@ -131,7 +131,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
fn map_children<L, O, F>( fn map_children<L, O, F>(
children: &[CalcNode<L>], children: &[CalcNode<L>],
map: &mut F, map: &mut F,
) -> Box<[CalcNode<O>]> ) -> crate::OwnedSlice<CalcNode<O>>
where where
L: CalcNodeLeaf, L: CalcNodeLeaf,
O: CalcNodeLeaf, O: CalcNodeLeaf,
@ -209,7 +209,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
pub fn simplify_and_sort_children(&mut self) { pub fn simplify_and_sort_children(&mut self) {
macro_rules! replace_self_with { macro_rules! replace_self_with {
($slot:expr) => {{ ($slot:expr) => {{
let dummy = Self::MinMax(Box::new([]), MinMaxOp::Max); let dummy = Self::MinMax(Default::default(), MinMaxOp::Max);
let result = mem::replace($slot, dummy); let result = mem::replace($slot, dummy);
mem::replace(self, result); mem::replace(self, result);
}}; }};
@ -315,7 +315,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
return replace_self_with!(&mut children_slot[0]); return replace_self_with!(&mut children_slot[0]);
} }
let mut children = mem::replace(children_slot, Box::new([])).into_vec(); let mut children = mem::replace(children_slot, Default::default()).into_vec();
if !sums_to_merge.is_empty() { if !sums_to_merge.is_empty() {
children.reserve(extra_kids - sums_to_merge.len()); children.reserve(extra_kids - sums_to_merge.len());
@ -347,7 +347,7 @@ impl<L: CalcNodeLeaf> CalcNode<L> {
replace_self_with!(&mut children[0]); replace_self_with!(&mut children[0]);
} else { } else {
// Else put our simplified children back. // Else put our simplified children back.
mem::replace(children_slot, children.into_boxed_slice()); mem::replace(children_slot, children.into_boxed_slice().into());
} }
}, },
Self::Leaf(ref mut l) => { Self::Leaf(ref mut l) => {

View file

@ -397,8 +397,7 @@ impl CalcNode {
let arguments = input let arguments = input
.parse_comma_separated(|input| { .parse_comma_separated(|input| {
Self::parse_argument(context, input, expected_unit) Self::parse_argument(context, input, expected_unit)
})? })?;
.into_boxed_slice();
let op = match function { let op = match function {
MathFunction::Min => MinMaxOp::Min, MathFunction::Min => MinMaxOp::Min,
@ -406,7 +405,7 @@ impl CalcNode {
_ => unreachable!(), _ => unreachable!(),
}; };
Ok(Self::MinMax(arguments, op)) Ok(Self::MinMax(arguments.into(), op))
}, },
} }
}) })
@ -452,7 +451,7 @@ impl CalcNode {
Ok(if sum.len() == 1 { Ok(if sum.len() == 1 {
sum.drain(..).next().unwrap() sum.drain(..).next().unwrap()
} else { } else {
Self::Sum(sum.into_boxed_slice()) Self::Sum(sum.into_boxed_slice().into())
}) })
} }