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,
|
||||
seen: &mut PropertyBitField,
|
||||
cacheable: &mut bool,
|
||||
error_reporter: Box<ParseErrorReporter + Send>) {
|
||||
error_reporter: &mut Box<ParseErrorReporter + Send>) {
|
||||
let declared_value = match *declaration {
|
||||
PropertyDeclaration::${property.camel_case}(ref declared_value) => {
|
||||
declared_value
|
||||
|
@ -176,7 +176,7 @@ pub mod longhands {
|
|||
.${property.ident}
|
||||
.clone()
|
||||
}
|
||||
}, error_reporter.clone()
|
||||
}, error_reporter
|
||||
);
|
||||
Arc::make_mut(&mut style.${THIS_STYLE_STRUCT.ident}).${property.ident} =
|
||||
computed_value;
|
||||
|
@ -537,7 +537,7 @@ pub mod longhands {
|
|||
context: &computed::Context,
|
||||
_seen: &mut PropertyBitField,
|
||||
_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 =
|
||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(
|
||||
*computed_value,
|
||||
|
@ -2239,7 +2239,7 @@ pub mod longhands {
|
|||
context: &computed::Context,
|
||||
_seen: &mut PropertyBitField,
|
||||
_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 =
|
||||
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(
|
||||
*computed_value,
|
||||
|
@ -5618,19 +5618,47 @@ mod property_bit_field {
|
|||
fn substitute_variables_${property.ident}<F, R>(
|
||||
value: &DeclaredValue<longhands::${property.ident}::SpecifiedValue>,
|
||||
custom_properties: &Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
f: F, error_reporter: Box<ParseErrorReporter + Send>)
|
||||
f: F,
|
||||
error_reporter: &mut Box<ParseErrorReporter + Send>)
|
||||
-> R
|
||||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>) -> R
|
||||
{
|
||||
if let DeclaredValue::WithVariables {
|
||||
ref css, first_token_type, ref base_url, from_shorthand
|
||||
} = *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(&
|
||||
::custom_properties::substitute(css, first_token_type, custom_properties)
|
||||
.and_then(|css| {
|
||||
// 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(
|
||||
::stylesheets::Origin::Author, base_url, error_reporter);
|
||||
::stylesheets::Origin::Author, base_url, (*error_reporter).clone());
|
||||
Parser::new(&css).parse_entirely(|input| {
|
||||
match from_shorthand {
|
||||
None => {
|
||||
|
@ -5656,9 +5684,6 @@ mod property_bit_field {
|
|||
DeclaredValue::${"Inherit" if property.style_struct.inherited else "Initial"}
|
||||
)
|
||||
)
|
||||
} else {
|
||||
f(value)
|
||||
}
|
||||
}
|
||||
% endif
|
||||
% endfor
|
||||
|
@ -6395,7 +6420,7 @@ fn cascade_with_cached_declarations(
|
|||
cached_style: &ComputedValues,
|
||||
custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
|
||||
context: &computed::Context,
|
||||
error_reporter: Box<ParseErrorReporter + Send>)
|
||||
mut error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> ComputedValues {
|
||||
% for style_struct in STYLE_STRUCTS:
|
||||
% if style_struct.inherited:
|
||||
|
@ -6439,7 +6464,7 @@ fn cascade_with_cached_declarations(
|
|||
.clone()
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!()
|
||||
}, error_reporter.clone()
|
||||
}, &mut error_reporter
|
||||
);
|
||||
Arc::make_mut(&mut style_${style_struct.ident})
|
||||
.${property.ident} = computed_value;
|
||||
|
@ -6495,7 +6520,7 @@ type CascadePropertyFn = extern "Rust" fn(declaration: &PropertyDeclaration,
|
|||
context: &computed::Context,
|
||||
seen: &mut PropertyBitField,
|
||||
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
|
||||
// properties.
|
||||
|
@ -6541,7 +6566,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
shareable: bool,
|
||||
parent_style: Option< &ComputedValues >,
|
||||
cached_style: Option< &ComputedValues >,
|
||||
error_reporter: Box<ParseErrorReporter + Send>)
|
||||
mut error_reporter: Box<ParseErrorReporter + Send>)
|
||||
-> (ComputedValues, bool) {
|
||||
let initial_values = &*INITIAL_VALUES;
|
||||
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()
|
||||
}
|
||||
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::Inherit => context.inherited_font_size,
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
}, error_reporter.clone()
|
||||
}, &mut error_reporter
|
||||
);
|
||||
}
|
||||
PropertyDeclaration::Color(ref value) => {
|
||||
|
@ -6656,35 +6681,35 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
DeclaredValue::Initial => longhands::color::get_initial_value(),
|
||||
DeclaredValue::Inherit => inherited_style.get_color().color.clone(),
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
}, error_reporter.clone()
|
||||
}, &mut error_reporter
|
||||
);
|
||||
}
|
||||
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) => {
|
||||
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::fixed => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
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) => {
|
||||
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) => {
|
||||
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;
|
||||
}
|
||||
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) => {
|
||||
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,
|
||||
_ => true,
|
||||
};
|
||||
|
@ -6692,7 +6717,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
% for side in ["top", "right", "bottom", "left"]:
|
||||
PropertyDeclaration::Border${side.capitalize()}Style(ref value) => {
|
||||
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,
|
||||
_ => true,
|
||||
};
|
||||
|
@ -6756,7 +6781,7 @@ pub fn cascade(viewport_size: Size2D<Au>,
|
|||
&context,
|
||||
&mut seen,
|
||||
&mut cacheable,
|
||||
error_reporter.clone());
|
||||
&mut error_reporter);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1518,10 +1518,12 @@ pub mod computed {
|
|||
}
|
||||
|
||||
impl CalcLengthOrPercentage {
|
||||
#[inline]
|
||||
pub fn length(&self) -> Au {
|
||||
self.length.unwrap_or(Au(0))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn percentage(&self) -> CSSFloat {
|
||||
self.percentage.unwrap_or(0.)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue