mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Replace usage of std::intrinsics::discriminant_value in properties.mako.rs
This commit is contained in:
parent
00af25b685
commit
f3d6859ab7
2 changed files with 27 additions and 32 deletions
|
@ -15,8 +15,6 @@ use std::boxed::Box as StdBox;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::intrinsics;
|
|
||||||
use std::mem;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use app_units::Au;
|
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 {
|
pub fn value(&self) -> String {
|
||||||
let mut value = String::new();
|
let mut value = String::new();
|
||||||
if let Err(_) = self.to_css(&mut value) {
|
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 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():
|
% for style_struct in data.active_style_structs():
|
||||||
fn clone_${style_struct.trait_name_lower}(&self) ->
|
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 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));
|
CASCADE_PROPERTY.with(|x| f(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1693,28 +1701,17 @@ pub type CascadePropertyFn<C /*: ComputedValues */> =
|
||||||
cacheable: &mut bool,
|
cacheable: &mut bool,
|
||||||
error_reporter: &mut StdBox<ParseErrorReporter + Send>);
|
error_reporter: &mut StdBox<ParseErrorReporter + Send>);
|
||||||
|
|
||||||
pub fn make_cascade_vec<C: ComputedValues>() -> Vec<Option<CascadePropertyFn<C>>> {
|
pub fn make_cascade_vec<C: ComputedValues>() -> Vec<CascadePropertyFn<C>> {
|
||||||
let mut result: Vec<Option<CascadePropertyFn<C>>> = Vec::new();
|
vec![
|
||||||
% for style_struct in data.active_style_structs():
|
% for property in data.longhands:
|
||||||
% for property in style_struct.longhands:
|
longhands::${property.ident}::cascade_property,
|
||||||
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);
|
|
||||||
% endfor
|
% endfor
|
||||||
% endfor
|
]
|
||||||
result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
|
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
|
||||||
// properties.
|
// properties.
|
||||||
thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<ServoComputedValues>>> = {
|
thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<ServoComputedValues>> = {
|
||||||
make_cascade_vec::<ServoComputedValues>()
|
make_cascade_vec::<ServoComputedValues>()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1840,15 +1837,13 @@ pub fn cascade<C: ComputedValues>(
|
||||||
{
|
{
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let discriminant = unsafe {
|
let discriminant = declaration.discriminant_value();
|
||||||
intrinsics::discriminant_value(declaration) as usize
|
(cascade_property[discriminant])(declaration,
|
||||||
};
|
inherited_style,
|
||||||
(cascade_property[discriminant].unwrap())(declaration,
|
&mut context,
|
||||||
inherited_style,
|
&mut seen,
|
||||||
&mut context,
|
&mut cacheable,
|
||||||
&mut seen,
|
&mut error_reporter);
|
||||||
&mut cacheable,
|
|
||||||
&mut error_reporter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
|
@ -106,7 +106,7 @@ impl ComputedValues for GeckoComputedValues {
|
||||||
|
|
||||||
fn initial_values() -> &'static Self { &*INITIAL_GECKO_VALUES }
|
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));
|
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
|
// This is a thread-local rather than a lazy static to avoid atomic operations when cascading
|
||||||
// properties.
|
// properties.
|
||||||
thread_local!(static CASCADE_PROPERTY: Vec<Option<CascadePropertyFn<GeckoComputedValues>>> = {
|
thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<GeckoComputedValues>> = {
|
||||||
make_cascade_vec::<GeckoComputedValues>()
|
make_cascade_vec::<GeckoComputedValues>()
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue