From f0b5d02901e16f38ec62236cf6a3a45c1108eafa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 5 Jul 2019 22:19:42 +0000 Subject: [PATCH] style: Use more compact and ffi-friendly types for some svg props. No functional change yet. Differential Revision: https://phabricator.services.mozilla.com/D36805 --- components/style/values/animated/mod.rs | 8 ++------ components/style/values/computed/svg.rs | 6 +++--- components/style/values/generics/svg.rs | 12 +++++++++--- components/style/values/specified/svg.rs | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 267ef0c8e6f..ea43d01112e 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -447,17 +447,13 @@ where } } -impl ToAnimatedZero for Box<[T]> +impl ToAnimatedZero for crate::OwnedSlice where T: ToAnimatedZero, { #[inline] fn to_animated_zero(&self) -> Result { - let v = self - .iter() - .map(|v| v.to_animated_zero()) - .collect::, _>>()?; - Ok(v.into_boxed_slice()) + self.iter().map(|v| v.to_animated_zero()).collect() } } diff --git a/components/style/values/computed/svg.rs b/components/style/values/computed/svg.rs index f05e9f836da..1b89e4e1aae 100644 --- a/components/style/values/computed/svg.rs +++ b/components/style/values/computed/svg.rs @@ -62,16 +62,16 @@ impl SVGWidth { } /// [ | | ]# | context-value -pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; +pub type SVGStrokeDashArray = generic::GenericSVGStrokeDashArray; impl Default for SVGStrokeDashArray { fn default() -> Self { - generic::SVGStrokeDashArray::Values(vec![]) + generic::SVGStrokeDashArray::Values(Default::default()) } } /// | context-fill-opacity | context-stroke-opacity -pub type SVGOpacity = generic::SVGOpacity; +pub type SVGOpacity = generic::GenericSVGOpacity; impl Default for SVGOpacity { fn default() -> Self { diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 0cd67dbf10e..315b530329f 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -171,14 +171,17 @@ pub enum SVGLength { ToResolvedValue, ToShmem, )] -pub enum SVGStrokeDashArray { +#[repr(C, u8)] +pub enum GenericSVGStrokeDashArray { /// `[ | | ]#` #[css(comma)] - Values(#[css(if_empty = "none", iterable)] Vec), + Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice), /// `context-value` ContextValue, } +pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray; + /// An SVG opacity value accepts `context-{fill,stroke}-opacity` in /// addition to opacity value. #[derive( @@ -197,7 +200,8 @@ pub enum SVGStrokeDashArray { ToResolvedValue, ToShmem, )] -pub enum SVGOpacity { +#[repr(C, u8)] +pub enum GenericSVGOpacity { /// `` Opacity(OpacityType), /// `context-fill-opacity` @@ -207,3 +211,5 @@ pub enum SVGOpacity { #[animation(error)] ContextStrokeOpacity, } + +pub use self::GenericSVGOpacity as SVGOpacity; diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index 9acfad34723..c6fb40ba0c0 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -80,14 +80,14 @@ impl Parse for SVGStrokeDashArray { NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always) }) }) { - return Ok(generic::SVGStrokeDashArray::Values(values)); + return Ok(generic::SVGStrokeDashArray::Values(values.into())); } try_match_ident_ignore_ascii_case! { input, "context-value" if is_context_value_enabled() => { Ok(generic::SVGStrokeDashArray::ContextValue) }, - "none" => Ok(generic::SVGStrokeDashArray::Values(vec![])), + "none" => Ok(generic::SVGStrokeDashArray::Values(Default::default())), } } }