diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2016-06-27 18:47:33 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2016-06-28 06:46:40 +0200 |
commit | f3d6859ab71a9de85fa4039575fb647cc2579b69 (patch) | |
tree | e8a220b4b002adf09ad37b034698e442ad9c7786 | |
parent | 00af25b6855b1c3cd2ddf5119478e9119efaffd9 (diff) | |
download | servo-f3d6859ab71a9de85fa4039575fb647cc2579b69.tar.gz servo-f3d6859ab71a9de85fa4039575fb647cc2579b69.zip |
Replace usage of std::intrinsics::discriminant_value in properties.mako.rs
-rw-r--r-- | components/style/properties/properties.mako.rs | 55 | ||||
-rw-r--r-- | ports/geckolib/properties.mako.rs | 4 |
2 files changed, 27 insertions, 32 deletions
diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 91b602375f5..2e5ab399482 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -15,8 +15,6 @@ use std::boxed::Box as StdBox; use std::collections::HashSet; use std::fmt; use std::fmt::Write; -use std::intrinsics; -use std::mem; use std::sync::Arc; use app_units::Au; @@ -839,6 +837,16 @@ impl PropertyDeclaration { } } + #[inline] + pub fn discriminant_value(&self) -> usize { + match *self { + % for i, property in enumerate(data.longhands): + PropertyDeclaration::${property.camel_case}(..) => ${i}, + % endfor + PropertyDeclaration::Custom(..) => ${len(data.longhands)} + } + } + pub fn value(&self) -> String { let mut value = String::new(); if let Err(_) = self.to_css(&mut value) { @@ -1221,7 +1229,7 @@ pub trait ComputedValues : Clone + Send + Sync + 'static { fn initial_values() -> &'static Self; - fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(f: F); + fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F); % for style_struct in data.active_style_structs(): fn clone_${style_struct.trait_name_lower}(&self) -> @@ -1292,7 +1300,7 @@ impl ComputedValues for ServoComputedValues { fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } - fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(f: F) { + fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F) { CASCADE_PROPERTY.with(|x| f(x)); } @@ -1693,28 +1701,17 @@ pub type CascadePropertyFn<C /*: ComputedValues */> = cacheable: &mut bool, error_reporter: &mut StdBox<ParseErrorReporter + Send>); -pub fn make_cascade_vec<C: ComputedValues>() -> Vec<Option<CascadePropertyFn<C>>> { - let mut result: Vec<Option<CascadePropertyFn<C>>> = Vec::new(); - % for style_struct in data.active_style_structs(): - % for property in style_struct.longhands: - let discriminant; - unsafe { - let variant = PropertyDeclaration::${property.camel_case}(mem::uninitialized()); - discriminant = intrinsics::discriminant_value(&variant) as usize; - mem::forget(variant); - } - while result.len() < discriminant + 1 { - result.push(None) - } - result[discriminant] = Some(longhands::${property.ident}::cascade_property); +pub fn make_cascade_vec<C: ComputedValues>() -> Vec<CascadePropertyFn<C>> { + vec![ + % for property in data.longhands: + longhands::${property.ident}::cascade_property, % endfor - % endfor - result + ] } // This is a thread-local rather than a lazy static to avoid atomic operations when cascading // properties. -thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<ServoComputedValues>>> = { +thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<ServoComputedValues>> = { make_cascade_vec::<ServoComputedValues>() }); @@ -1840,15 +1837,13 @@ pub fn cascade<C: ComputedValues>( { continue } - let discriminant = unsafe { - intrinsics::discriminant_value(declaration) as usize - }; - (cascade_property[discriminant].unwrap())(declaration, - inherited_style, - &mut context, - &mut seen, - &mut cacheable, - &mut error_reporter); + let discriminant = declaration.discriminant_value(); + (cascade_property[discriminant])(declaration, + inherited_style, + &mut context, + &mut seen, + &mut cacheable, + &mut error_reporter); } } % endfor diff --git a/ports/geckolib/properties.mako.rs b/ports/geckolib/properties.mako.rs index fa694551d2c..7a3f79e6748 100644 --- a/ports/geckolib/properties.mako.rs +++ b/ports/geckolib/properties.mako.rs @@ -106,7 +106,7 @@ impl ComputedValues for GeckoComputedValues { fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES } - fn do_cascade_property<F: FnOnce(&Vec<Option<CascadePropertyFn<Self>>>)>(f: F) { + fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F) { CASCADE_PROPERTY.with(|x| f(x)); } @@ -1135,6 +1135,6 @@ lazy_static! { // This is a thread-local rather than a lazy static to avoid atomic operations when cascading // properties. -thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<GeckoComputedValues>>> = { +thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<GeckoComputedValues>> = { make_cascade_vec::<GeckoComputedValues>() }); |