aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-06-27 12:00:40 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-06-27 23:37:51 +0200
commit813883e1bda5aa028b1bd3940fb7718fc01b65c6 (patch)
treee932894c62a26ac2e642b77350bf59f83e2ad5b6
parentda9d2001dbb285204e19a95c092c696fbecea1d5 (diff)
downloadservo-813883e1bda5aa028b1bd3940fb7718fc01b65c6.tar.gz
servo-813883e1bda5aa028b1bd3940fb7718fc01b65c6.zip
Don't use SmallVec<[T; 1]> for computed values with an empty default
-rw-r--r--components/style/properties/helpers.mako.rs19
-rw-r--r--components/style/properties/helpers/animated_properties.mako.rs64
2 files changed, 48 insertions, 35 deletions
diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs
index 808fa26644d..13a64beaa5f 100644
--- a/components/style/properties/helpers.mako.rs
+++ b/components/style/properties/helpers.mako.rs
@@ -83,6 +83,7 @@
delegate_animate=False, separator='Comma', **kwargs)">
<%call expr="longhand(name, vector=True, **kwargs)">
% if not gecko_only:
+ #[allow(unused_imports)]
use smallvec::SmallVec;
use std::fmt;
#[allow(unused_imports)]
@@ -113,13 +114,23 @@
pub mod computed_value {
pub use super::single_value::computed_value as single_value;
pub use self::single_value::T as SingleComputedValue;
+ % if allow_empty and allow_empty != "NotInitial":
+ use std::vec::IntoIter;
+ % else:
use smallvec::{IntoIter, SmallVec};
+ % endif
use values::computed::ComputedVecIter;
/// The computed value, effectively a list of single values.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
- pub struct T(pub SmallVec<[single_value::T; 1]>);
+ pub struct T(
+ % if allow_empty and allow_empty != "NotInitial":
+ pub Vec<single_value::T>,
+ % else:
+ pub SmallVec<[single_value::T; 1]>,
+ % endif
+ );
% if delegate_animate:
use properties::animated_properties::Animatable;
@@ -149,7 +160,11 @@
impl IntoIterator for T {
type Item = single_value::T;
+ % if allow_empty and allow_empty != "NotInitial":
+ type IntoIter = IntoIter<single_value::T>;
+ % else:
type IntoIter = IntoIter<[single_value::T; 1]>;
+ % endif
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
@@ -207,7 +222,7 @@
pub fn get_initial_value() -> computed_value::T {
% if allow_empty and allow_empty != "NotInitial":
- computed_value::T(SmallVec::new())
+ computed_value::T(vec![])
% else:
let mut v = SmallVec::new();
v.push(single_value::get_initial_value());
diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs
index 99b2cc377f6..854e24f77e6 100644
--- a/components/style/properties/helpers/animated_properties.mako.rs
+++ b/components/style/properties/helpers/animated_properties.mako.rs
@@ -808,31 +808,37 @@ pub trait RepeatableListAnimatable: Animatable {}
impl RepeatableListAnimatable for LengthOrPercentage {}
impl RepeatableListAnimatable for Either<f32, LengthOrPercentage> {}
-impl<T: RepeatableListAnimatable> Animatable for SmallVec<[T; 1]> {
- fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
- -> Result<Self, ()> {
- use num_integer::lcm;
- let len = lcm(self.len(), other.len());
- self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
- me.add_weighted(you, self_portion, other_portion)
- }).collect()
- }
+macro_rules! repeated_vec_impl {
+ ($($ty:ty),*) => {
+ $(impl<T: RepeatableListAnimatable> Animatable for $ty {
+ fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
+ -> Result<Self, ()> {
+ use num_integer::lcm;
+ let len = lcm(self.len(), other.len());
+ self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
+ me.add_weighted(you, self_portion, other_portion)
+ }).collect()
+ }
- #[inline]
- fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
- self.compute_squared_distance(other).map(|sd| sd.sqrt())
- }
+ #[inline]
+ fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
+ self.compute_squared_distance(other).map(|sd| sd.sqrt())
+ }
- #[inline]
- fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
- use num_integer::lcm;
- let len = lcm(self.len(), other.len());
- self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
- me.compute_squared_distance(you)
- }).collect::<Result<Vec<_>, _>>().map(|d| d.iter().sum())
- }
+ #[inline]
+ fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
+ use num_integer::lcm;
+ let len = lcm(self.len(), other.len());
+ self.iter().cycle().zip(other.iter().cycle()).take(len).map(|(me, you)| {
+ me.compute_squared_distance(you)
+ }).sum()
+ }
+ })*
+ };
}
+repeated_vec_impl!(SmallVec<[T; 1]>, Vec<T>);
+
/// https://drafts.csswg.org/css-transitions/#animtype-number
impl Animatable for Au {
#[inline]
@@ -3053,9 +3059,9 @@ pub struct IntermediateShadow {
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)]
/// Intermediate type for box-shadow list and text-shadow list.
-pub struct IntermediateShadowList(pub SmallVec<[IntermediateShadow; 1]>);
+pub struct IntermediateShadowList(pub Vec<IntermediateShadow>);
-type ShadowList = SmallVec<[Shadow; 1]>;
+type ShadowList = Vec<Shadow>;
impl From<IntermediateShadowList> for ShadowList {
fn from(shadow_list: IntermediateShadowList) -> Self {
@@ -3172,11 +3178,7 @@ impl Animatable for IntermediateShadowList {
let max_len = cmp::max(self.0.len(), other.0.len());
- let mut result = if max_len > 1 {
- SmallVec::from_vec(Vec::with_capacity(max_len))
- } else {
- SmallVec::new()
- };
+ let mut result = Vec::with_capacity(max_len);
for i in 0..max_len {
let shadow = match (self.0.get(i), other.0.get(i)) {
@@ -3202,11 +3204,7 @@ impl Animatable for IntermediateShadowList {
fn add(&self, other: &Self) -> Result<Self, ()> {
let len = self.0.len() + other.0.len();
- let mut result = if len > 1 {
- SmallVec::from_vec(Vec::with_capacity(len))
- } else {
- SmallVec::new()
- };
+ let mut result = Vec::with_capacity(len);
result.extend(self.0.iter().cloned());
result.extend(other.0.iter().cloned());