style: Use OwnedSlice in the specified and computed values of most vector properties.

This is just a refactor in the right direction. Eventual goal is:

 * All inherited properties use ArcSlice<>.
 * All reset properties use OwnedSlice<> (or ThinVec<>).

No conversion happens at all, so we can remove all that glue, and also
compute_iter and co.

Of course there's work to do, but this is a step towards that.

Differential Revision: https://phabricator.services.mozilla.com/D30127
This commit is contained in:
Emilio Cobos Álvarez 2019-05-16 23:21:37 +00:00
parent b61eb84d96
commit ab8776a144
9 changed files with 100 additions and 107 deletions

View file

@ -40,11 +40,11 @@
let mut background_color = None;
% for name in "image position_x position_y repeat size attachment origin clip".split():
// Vec grows from 0 to 4 by default on first push(). So allocate
// with capacity 1, so in the common case of only one item we don't
// way overallocate. Note that we always push at least one item if
// parsing succeeds.
let mut background_${name} = background_${name}::SpecifiedValue(Vec::with_capacity(1));
// Vec grows from 0 to 4 by default on first push(). So allocate with
// capacity 1, so in the common case of only one item we don't way
// overallocate, then shrink. Note that we always push at least one
// item if parsing succeeds.
let mut background_${name} = Vec::with_capacity(1);
% endfor
input.parse_comma_separated(|input| {
// background-color can only be in the last element, so if it
@ -99,17 +99,17 @@
any = any || background_color.is_some();
if any {
if let Some(position) = position {
background_position_x.0.push(position.horizontal);
background_position_y.0.push(position.vertical);
background_position_x.push(position.horizontal);
background_position_y.push(position.vertical);
} else {
background_position_x.0.push(PositionComponent::zero());
background_position_y.0.push(PositionComponent::zero());
background_position_x.push(PositionComponent::zero());
background_position_y.push(PositionComponent::zero());
}
% for name in "image repeat size attachment origin clip".split():
if let Some(bg_${name}) = ${name} {
background_${name}.0.push(bg_${name});
background_${name}.push(bg_${name});
} else {
background_${name}.0.push(background_${name}::single_value
background_${name}.push(background_${name}::single_value
::get_initial_specified_value());
}
% endfor
@ -121,14 +121,9 @@
Ok(expanded! {
background_color: background_color.unwrap_or(Color::transparent()),
background_image: background_image,
background_position_x: background_position_x,
background_position_y: background_position_y,
background_repeat: background_repeat,
background_attachment: background_attachment,
background_size: background_size,
background_origin: background_origin,
background_clip: background_clip,
% for name in "image position_x position_y repeat size attachment origin clip".split():
background_${name}: background_${name}::SpecifiedValue(background_${name}.into()),
% endfor
})
}
@ -209,16 +204,16 @@
) -> Result<Longhands, ParseError<'i>> {
// Vec grows from 0 to 4 by default on first push(). So allocate with
// capacity 1, so in the common case of only one item we don't way
// overallocate. Note that we always push at least one item if parsing
// succeeds.
let mut position_x = background_position_x::SpecifiedValue(Vec::with_capacity(1));
let mut position_y = background_position_y::SpecifiedValue(Vec::with_capacity(1));
// overallocate, then shrink. Note that we always push at least one
// item if parsing succeeds.
let mut position_x = Vec::with_capacity(1);
let mut position_y = Vec::with_capacity(1);
let mut any = false;
input.parse_comma_separated(|input| {
let value = Position::parse_quirky(context, input, AllowQuirks::Yes)?;
position_x.0.push(value.horizontal);
position_y.0.push(value.vertical);
position_x.push(value.horizontal);
position_y.push(value.vertical);
any = true;
Ok(())
})?;
@ -227,8 +222,8 @@
}
Ok(expanded! {
background_position_x: position_x,
background_position_y: position_y,
background_position_x: background_position_x::SpecifiedValue(position_x.into()),
background_position_y: background_position_y::SpecifiedValue(position_y.into()),
})
}

View file

@ -137,7 +137,7 @@ macro_rules! try_parse_one {
Ok(expanded! {
% for prop in "property duration timing_function delay".split():
transition_${prop}: transition_${prop}::SpecifiedValue(${prop}s),
transition_${prop}: transition_${prop}::SpecifiedValue(${prop}s.into()),
% endfor
})
}
@ -266,7 +266,7 @@ macro_rules! try_parse_one {
Ok(expanded! {
% for prop in props:
animation_${prop}: animation_${prop}::SpecifiedValue(${prop}s),
animation_${prop}: animation_${prop}::SpecifiedValue(${prop}s.into()),
% endfor
})
}

View file

@ -42,11 +42,11 @@
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
% for name in "image mode position_x position_y size repeat origin clip composite".split():
// Vec grows from 0 to 4 by default on first push(). So allocate
// with capacity 1, so in the common case of only one item we don't
// way overallocate. Note that we always push at least one item if
// parsing succeeds.
let mut mask_${name} = mask_${name}::SpecifiedValue(Vec::with_capacity(1));
// Vec grows from 0 to 4 by default on first push(). So allocate with
// capacity 1, so in the common case of only one item we don't way
// overallocate, then shrink. Note that we always push at least one
// item if parsing succeeds.
let mut mask_${name} = Vec::with_capacity(1);
% endfor
input.parse_comma_separated(|input| {
@ -96,17 +96,17 @@
% endfor
if any {
if let Some(position) = position {
mask_position_x.0.push(position.horizontal);
mask_position_y.0.push(position.vertical);
mask_position_x.push(position.horizontal);
mask_position_y.push(position.vertical);
} else {
mask_position_x.0.push(PositionComponent::zero());
mask_position_y.0.push(PositionComponent::zero());
mask_position_x.push(PositionComponent::zero());
mask_position_y.push(PositionComponent::zero());
}
% for name in "image mode size repeat origin clip composite".split():
if let Some(m_${name}) = ${name} {
mask_${name}.0.push(m_${name});
mask_${name}.push(m_${name});
} else {
mask_${name}.0.push(mask_${name}::single_value
mask_${name}.push(mask_${name}::single_value
::get_initial_specified_value());
}
% endfor
@ -118,7 +118,7 @@
Ok(expanded! {
% for name in "image mode position_x position_y size repeat origin clip composite".split():
mask_${name}: mask_${name},
mask_${name}: mask_${name}::SpecifiedValue(mask_${name}.into()),
% endfor
})
}
@ -209,16 +209,16 @@
) -> Result<Longhands, ParseError<'i>> {
// Vec grows from 0 to 4 by default on first push(). So allocate with
// capacity 1, so in the common case of only one item we don't way
// overallocate. Note that we always push at least one item if parsing
// succeeds.
let mut position_x = mask_position_x::SpecifiedValue(Vec::with_capacity(1));
let mut position_y = mask_position_y::SpecifiedValue(Vec::with_capacity(1));
// overallocate, then shrink. Note that we always push at least one
// item if parsing succeeds.
let mut position_x = Vec::with_capacity(1);
let mut position_y = Vec::with_capacity(1);
let mut any = false;
input.parse_comma_separated(|input| {
let value = Position::parse(context, input)?;
position_x.0.push(value.horizontal);
position_y.0.push(value.vertical);
position_x.push(value.horizontal);
position_y.push(value.vertical);
any = true;
Ok(())
})?;
@ -227,9 +227,10 @@
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
Ok(expanded! {
mask_position_x: position_x,
mask_position_y: position_y,
mask_position_x: mask_position_x::SpecifiedValue(position_x.into()),
mask_position_y: mask_position_y::SpecifiedValue(position_y.into()),
})
}