From 85752fa479064678238c66913f44667428860f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 16 May 2019 23:23:28 +0000 Subject: [PATCH] style: Use OwnedSlice for will-change. We could use ArcSlice if wanted I guess, your call. Though will change is not supposed to be used very frequently. Differential Revision: https://phabricator.services.mozilla.com/D30548 --- components/style/properties/gecko.mako.rs | 62 +---------------------- components/style/values/specified/box.rs | 47 ++++++++--------- 2 files changed, 25 insertions(+), 84 deletions(-) diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 85befa09a3c..13b30b53b1b 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -2513,7 +2513,7 @@ fn static_assert() { transition-timing-function transition-property transform-style rotate scroll-snap-points-x scroll-snap-points-y - scroll-snap-coordinate -moz-binding will-change + scroll-snap-coordinate -moz-binding offset-path shape-outside translate scale -webkit-line-clamp""" %> <%self:impl_trait style_struct_name="Box" skip_longhands="${skip_box_longhands}"> @@ -2829,66 +2829,6 @@ fn static_assert() { ${impl_individual_transform('translate', 'Translate', 'mSpecifiedTranslate')} ${impl_individual_transform('scale', 'Scale', 'mSpecifiedScale')} - pub fn set_will_change(&mut self, v: longhands::will_change::computed_value::T) { - use crate::gecko_bindings::bindings::{Gecko_AppendWillChange, Gecko_ClearWillChange}; - use crate::values::specified::box_::{WillChangeBits, WillChange}; - - match v { - WillChange::AnimateableFeatures { features, bits } => { - unsafe { - Gecko_ClearWillChange(&mut *self.gecko, features.len()); - } - - for feature in features.iter() { - unsafe { - Gecko_AppendWillChange(&mut *self.gecko, feature.0.as_ptr()) - } - } - - self.gecko.mWillChangeBitField = bits; - }, - WillChange::Auto => { - unsafe { - Gecko_ClearWillChange(&mut *self.gecko, 0); - } - self.gecko.mWillChangeBitField = WillChangeBits::empty(); - }, - }; - } - - pub fn copy_will_change_from(&mut self, other: &Self) { - use crate::gecko_bindings::bindings::Gecko_CopyWillChangeFrom; - - self.gecko.mWillChangeBitField = other.gecko.mWillChangeBitField; - unsafe { - Gecko_CopyWillChangeFrom(&mut *self.gecko, &*other.gecko); - } - } - - pub fn reset_will_change(&mut self, other: &Self) { - self.copy_will_change_from(other) - } - - pub fn clone_will_change(&self) -> longhands::will_change::computed_value::T { - use crate::values::CustomIdent; - use crate::values::specified::box_::WillChange; - - if self.gecko.mWillChange.len() == 0 { - return WillChange::Auto - } - - let custom_idents: Vec = self.gecko.mWillChange.iter().map(|gecko_atom| { - unsafe { - CustomIdent(Atom::from_raw(gecko_atom.mRawPtr)) - } - }).collect(); - - WillChange::AnimateableFeatures { - features: custom_idents.into_boxed_slice(), - bits: self.gecko.mWillChangeBitField, - } - } - <% impl_shape_source("shape_outside", "mShapeOutside") %> pub fn set_offset_path(&mut self, v: longhands::offset_path::computed_value::T) { diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 31a79c141e1..542976d45ba 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -642,6 +642,7 @@ pub enum OverflowClipBox { #[derive( Clone, Debug, + Default, MallocSizeOf, PartialEq, SpecifiedValueInfo, @@ -650,38 +651,38 @@ pub enum OverflowClipBox { ToResolvedValue, ToShmem, )] -/// Provides a rendering hint to the user agent, -/// stating what kinds of changes the author expects -/// to perform on the element +#[css(comma)] +#[repr(C)] +/// Provides a rendering hint to the user agent, stating what kinds of changes +/// the author expects to perform on the element. +/// +/// `auto` is represented by an empty `features` list. /// /// -pub enum WillChange { - /// Expresses no particular intent - Auto, - /// - #[css(comma)] - AnimateableFeatures { - /// The features that are supposed to change. - #[css(iterable)] - features: Box<[CustomIdent]>, - /// A bitfield with the kind of change that the value will create, based - /// on the above field. - #[css(skip)] - bits: WillChangeBits, - }, +pub struct WillChange { + /// The features that are supposed to change. + /// + /// TODO(emilio): Consider using ArcSlice since we just clone them from the + /// specified value? That'd save an allocation, which could be worth it. + #[css(iterable, if_empty = "auto")] + features: crate::OwnedSlice, + /// A bitfield with the kind of change that the value will create, based + /// on the above field. + #[css(skip)] + bits: WillChangeBits, } impl WillChange { #[inline] /// Get default value of `will-change` as `auto` - pub fn auto() -> WillChange { - WillChange::Auto + pub fn auto() -> Self { + Self::default() } } bitflags! { /// The change bits that we care about. - #[derive(MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)] + #[derive(Default, MallocSizeOf, SpecifiedValueInfo, ToComputedValue, ToResolvedValue, ToShmem)] #[repr(C)] pub struct WillChangeBits: u8 { /// Whether the stacking context will change. @@ -746,7 +747,7 @@ impl Parse for WillChange { .try(|input| input.expect_ident_matching("auto")) .is_ok() { - return Ok(WillChange::Auto); + return Ok(Self::default()); } let mut bits = WillChangeBits::empty(); @@ -767,8 +768,8 @@ impl Parse for WillChange { Ok(ident) })?; - Ok(WillChange::AnimateableFeatures { - features: custom_idents.into_boxed_slice(), + Ok(Self { + features: custom_idents.into(), bits, }) }