mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #8974 - pcwalton:simple-style-optzns, r=SimonSapin
Implement some trivial restyling optimizations. These were discovered during profiling. r? @SimonSapin <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8974) <!-- Reviewable:end -->
This commit is contained in:
commit
1d7689cb3f
2 changed files with 79 additions and 52 deletions
|
@ -147,7 +147,7 @@ pub mod longhands {
|
||||||
context: &computed::Context,
|
context: &computed::Context,
|
||||||
seen: &mut PropertyBitField,
|
seen: &mut PropertyBitField,
|
||||||
cacheable: &mut bool,
|
cacheable: &mut bool,
|
||||||
error_reporter: Box<ParseErrorReporter + Send>) {
|
error_reporter: &mut Box<ParseErrorReporter + Send>) {
|
||||||
let declared_value = match *declaration {
|
let declared_value = match *declaration {
|
||||||
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
||||||
declared_value
|
declared_value
|
||||||
|
@ -176,7 +176,7 @@ pub mod longhands {
|
||||||
.${property.ident}
|
.${property.ident}
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
}, error_reporter.clone()
|
}, error_reporter
|
||||||
);
|
);
|
||||||
Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||||
computed_value;
|
computed_value;
|
||||||
|
@ -537,7 +537,7 @@ pub mod longhands {
|
||||||
context: &computed::Context,
|
context: &computed::Context,
|
||||||
_seen: &mut PropertyBitField,
|
_seen: &mut PropertyBitField,
|
||||||
_cacheable: &mut bool,
|
_cacheable: &mut bool,
|
||||||
_error_reporter: Box<ParseErrorReporter + Send>) {
|
_error_reporter: &mut Box<ParseErrorReporter + Send>) {
|
||||||
Arc::make_mut(&mut style.box_)._servo_display_for_hypothetical_box =
|
Arc::make_mut(&mut style.box_)._servo_display_for_hypothetical_box =
|
||||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(
|
longhands::_servo_display_for_hypothetical_box::derive_from_display(
|
||||||
*computed_value,
|
*computed_value,
|
||||||
|
@ -2239,7 +2239,7 @@ pub mod longhands {
|
||||||
context: &computed::Context,
|
context: &computed::Context,
|
||||||
_seen: &mut PropertyBitField,
|
_seen: &mut PropertyBitField,
|
||||||
_cacheable: &mut bool,
|
_cacheable: &mut bool,
|
||||||
_error_reporter: Box<ParseErrorReporter + Send>) {
|
_error_reporter: &mut Box<ParseErrorReporter + Send>) {
|
||||||
Arc::make_mut(&mut style.inheritedtext)._servo_text_decorations_in_effect =
|
Arc::make_mut(&mut style.inheritedtext)._servo_text_decorations_in_effect =
|
||||||
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(
|
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(
|
||||||
*computed_value,
|
*computed_value,
|
||||||
|
@ -5618,19 +5618,47 @@ mod property_bit_field {
|
||||||
fn substitute_variables_${property.ident}<F, R>(
|
fn substitute_variables_${property.ident}<F, R>(
|
||||||
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
||||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
f: F, error_reporter: Box<ParseErrorReporter + Send>)
|
f: F,
|
||||||
|
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
||||||
-> R
|
-> R
|
||||||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
|
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
|
||||||
{
|
{
|
||||||
if let DeclaredValue::WithVariables {
|
if let DeclaredValue::WithVariables {
|
||||||
ref css, first_token_type, ref base_url, from_shorthand
|
ref css, first_token_type, ref base_url, from_shorthand
|
||||||
} = *value {
|
} = *value {
|
||||||
|
substitute_variables_${property.ident}_slow(css,
|
||||||
|
first_token_type,
|
||||||
|
base_url,
|
||||||
|
from_shorthand,
|
||||||
|
custom_properties,
|
||||||
|
f,
|
||||||
|
error_reporter)
|
||||||
|
} else {
|
||||||
|
f(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn substitute_variables_${property.ident}_slow<F, R>(
|
||||||
|
css: &String,
|
||||||
|
first_token_type: TokenSerializationType,
|
||||||
|
base_url: &Url,
|
||||||
|
from_shorthand: Option<Shorthand>,
|
||||||
|
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
|
f: F,
|
||||||
|
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
||||||
|
-> R
|
||||||
|
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>)
|
||||||
|
-> R {
|
||||||
f(&
|
f(&
|
||||||
::custom_properties::substitute(css, first_token_type, custom_properties)
|
::custom_properties::substitute(css, first_token_type, custom_properties)
|
||||||
.and_then(|css| {
|
.and_then(|css| {
|
||||||
// As of this writing, only the base URL is used for property values:
|
// As of this writing, only the base URL is used for property values:
|
||||||
|
//
|
||||||
|
// FIXME(pcwalton): Cloning the error reporter is slow! But so are custom
|
||||||
|
// properties, so whatever...
|
||||||
let context = ParserContext::new(
|
let context = ParserContext::new(
|
||||||
::stylesheets::Origin::Author, base_url, error_reporter);
|
::stylesheets::Origin::Author, base_url, (*error_reporter).clone());
|
||||||
Parser::new(&css).parse_entirely(|input| {
|
Parser::new(&css).parse_entirely(|input| {
|
||||||
match from_shorthand {
|
match from_shorthand {
|
||||||
None => {
|
None => {
|
||||||
|
@ -5656,9 +5684,6 @@ mod property_bit_field {
|
||||||
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"}
|
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else {
|
|
||||||
f(value)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -6395,7 +6420,7 @@ fn cascade_with_cached_declarations(
|
||||||
cached_style: &ComputedValues,
|
cached_style: &ComputedValues,
|
||||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||||
context: &computed::Context,
|
context: &computed::Context,
|
||||||
error_reporter: Box<ParseErrorReporter + Send>)
|
mut error_reporter: Box<ParseErrorReporter + Send>)
|
||||||
-> ComputedValues {
|
-> ComputedValues {
|
||||||
% for style_struct in STYLE_STRUCTS:
|
% for style_struct in STYLE_STRUCTS:
|
||||||
% if style_struct.inherited:
|
% if style_struct.inherited:
|
||||||
|
@ -6439,7 +6464,7 @@ fn cascade_with_cached_declarations(
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||||
}, error_reporter.clone()
|
}, &mut error_reporter
|
||||||
);
|
);
|
||||||
Arc::make_mut(&mut style_${style_struct.ident})
|
Arc::make_mut(&mut style_${style_struct.ident})
|
||||||
.${property.ident} = computed_value;
|
.${property.ident} = computed_value;
|
||||||
|
@ -6495,7 +6520,7 @@ type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration,
|
||||||
context: &computed::Context,
|
context: &computed::Context,
|
||||||
seen: &mut PropertyBitField,
|
seen: &mut PropertyBitField,
|
||||||
cacheable: &mut bool,
|
cacheable: &mut bool,
|
||||||
error_reporter: Box<ParseErrorReporter + Send>);
|
error_reporter: &mut Box<ParseErrorReporter + Send>);
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -6541,7 +6566,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
parent_style: Option< &ComputedValues >,
|
parent_style: Option< &ComputedValues >,
|
||||||
cached_style: Option< &ComputedValues >,
|
cached_style: Option< &ComputedValues >,
|
||||||
error_reporter: Box<ParseErrorReporter + Send>)
|
mut error_reporter: Box<ParseErrorReporter + Send>)
|
||||||
-> (ComputedValues, bool) {
|
-> (ComputedValues, bool) {
|
||||||
let initial_values = &*INITIAL_VALUES;
|
let initial_values = &*INITIAL_VALUES;
|
||||||
let (is_root_element, inherited_style) = match parent_style {
|
let (is_root_element, inherited_style) = match parent_style {
|
||||||
|
@ -6605,7 +6630,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
inherited_style.$style_struct_getter().$property.clone()
|
inherited_style.$style_struct_getter().$property.clone()
|
||||||
}
|
}
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||||
}, $error_reporter.clone()
|
}, &mut $error_reporter
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
);
|
);
|
||||||
|
@ -6644,7 +6669,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
DeclaredValue::Initial => longhands::font_size::get_initial_value(),
|
DeclaredValue::Initial => longhands::font_size::get_initial_value(),
|
||||||
DeclaredValue::Inherit => context.inherited_font_size,
|
DeclaredValue::Inherit => context.inherited_font_size,
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
}, error_reporter.clone()
|
}, &mut error_reporter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::Color(ref value) => {
|
PropertyDeclaration::Color(ref value) => {
|
||||||
|
@ -6656,35 +6681,35 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
DeclaredValue::Initial => longhands::color::get_initial_value(),
|
DeclaredValue::Initial => longhands::color::get_initial_value(),
|
||||||
DeclaredValue::Inherit => inherited_style.get_color().color.clone(),
|
DeclaredValue::Inherit => inherited_style.get_color().color.clone(),
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
}, error_reporter.clone()
|
}, &mut error_reporter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::Display(ref value) => {
|
PropertyDeclaration::Display(ref value) => {
|
||||||
context.display = get_specified!(get_box, display, value, error_reporter.clone());
|
context.display = get_specified!(get_box, display, value, error_reporter);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::Position(ref value) => {
|
PropertyDeclaration::Position(ref value) => {
|
||||||
context.positioned = match get_specified!(get_box, position, value, error_reporter.clone()) {
|
context.positioned = match get_specified!(get_box, position, value, error_reporter) {
|
||||||
longhands::position::SpecifiedValue::absolute |
|
longhands::position::SpecifiedValue::absolute |
|
||||||
longhands::position::SpecifiedValue::fixed => true,
|
longhands::position::SpecifiedValue::fixed => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PropertyDeclaration::OverflowX(ref value) => {
|
PropertyDeclaration::OverflowX(ref value) => {
|
||||||
context.overflow_x = get_specified!(get_box, overflow_x, value, error_reporter.clone());
|
context.overflow_x = get_specified!(get_box, overflow_x, value, error_reporter);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::OverflowY(ref value) => {
|
PropertyDeclaration::OverflowY(ref value) => {
|
||||||
context.overflow_y = get_specified!(get_box, overflow_y, value, error_reporter.clone());
|
context.overflow_y = get_specified!(get_box, overflow_y, value, error_reporter);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::Float(ref value) => {
|
PropertyDeclaration::Float(ref value) => {
|
||||||
context.floated = get_specified!(get_box, float, value, error_reporter.clone())
|
context.floated = get_specified!(get_box, float, value, error_reporter)
|
||||||
!= longhands::float::SpecifiedValue::none;
|
!= longhands::float::SpecifiedValue::none;
|
||||||
}
|
}
|
||||||
PropertyDeclaration::TextDecoration(ref value) => {
|
PropertyDeclaration::TextDecoration(ref value) => {
|
||||||
context.text_decoration = get_specified!(get_text, text_decoration, value, error_reporter.clone());
|
context.text_decoration = get_specified!(get_text, text_decoration, value, error_reporter);
|
||||||
}
|
}
|
||||||
PropertyDeclaration::OutlineStyle(ref value) => {
|
PropertyDeclaration::OutlineStyle(ref value) => {
|
||||||
context.outline_style_present =
|
context.outline_style_present =
|
||||||
match get_specified!(get_outline, outline_style, value, error_reporter.clone()) {
|
match get_specified!(get_outline, outline_style, value, error_reporter) {
|
||||||
BorderStyle::none => false,
|
BorderStyle::none => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
|
@ -6692,7 +6717,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
% for side in ["top", "right", "bottom", "left"]:
|
% for side in ["top", "right", "bottom", "left"]:
|
||||||
PropertyDeclaration::Border${side.capitalize()}Style(ref value) => {
|
PropertyDeclaration::Border${side.capitalize()}Style(ref value) => {
|
||||||
context.border_${side}_present =
|
context.border_${side}_present =
|
||||||
match get_specified!(get_border, border_${side}_style, value, error_reporter.clone()) {
|
match get_specified!(get_border, border_${side}_style, value, error_reporter) {
|
||||||
BorderStyle::none | BorderStyle::hidden => false,
|
BorderStyle::none | BorderStyle::hidden => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
|
@ -6756,7 +6781,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
||||||
&context,
|
&context,
|
||||||
&mut seen,
|
&mut seen,
|
||||||
&mut cacheable,
|
&mut cacheable,
|
||||||
error_reporter.clone());
|
&mut error_reporter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1518,10 +1518,12 @@ pub mod computed {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CalcLengthOrPercentage {
|
impl CalcLengthOrPercentage {
|
||||||
|
#[inline]
|
||||||
pub fn length(&self) -> Au {
|
pub fn length(&self) -> Au {
|
||||||
self.length.unwrap_or(Au(0))
|
self.length.unwrap_or(Au(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn percentage(&self) -> CSSFloat {
|
pub fn percentage(&self) -> CSSFloat {
|
||||||
self.percentage.unwrap_or(0.)
|
self.percentage.unwrap_or(0.)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue