mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Cache font-style and text-decoration to speed up can_merge_with_box()
This commit is contained in:
parent
c246188605
commit
9a3a6f2829
1 changed files with 91 additions and 37 deletions
|
@ -114,6 +114,11 @@ impl TextRenderBox {
|
||||||
pub struct UnscannedTextRenderBox {
|
pub struct UnscannedTextRenderBox {
|
||||||
base: RenderBoxBase,
|
base: RenderBoxBase,
|
||||||
text: ~str,
|
text: ~str,
|
||||||
|
|
||||||
|
// Cache font-style and text-decoration to check whether
|
||||||
|
// this box can merge with another render box.
|
||||||
|
font_style: Option<FontStyle>,
|
||||||
|
text_decoration: Option<CSSTextDecoration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnscannedTextRenderBox {
|
impl UnscannedTextRenderBox {
|
||||||
|
@ -128,6 +133,8 @@ impl UnscannedTextRenderBox {
|
||||||
UnscannedTextRenderBox {
|
UnscannedTextRenderBox {
|
||||||
base: base,
|
base: base,
|
||||||
text: text_node.element.data.to_str(),
|
text: text_node.element.data.to_str(),
|
||||||
|
font_style: None,
|
||||||
|
text_decoration: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -824,9 +831,10 @@ impl RenderBox {
|
||||||
|
|
||||||
/// Converts this node's computed style to a font style used for rendering.
|
/// Converts this node's computed style to a font style used for rendering.
|
||||||
pub fn font_style(&self) -> FontStyle {
|
pub fn font_style(&self) -> FontStyle {
|
||||||
let my_style = self.nearest_ancestor_element().style();
|
fn get_font_style(element: AbstractNode<LayoutView>) -> FontStyle {
|
||||||
|
let my_style = element.style();
|
||||||
|
|
||||||
debug!("(font style) start: %?", self.nearest_ancestor_element().type_id());
|
debug!("(font style) start: %?", element.type_id());
|
||||||
|
|
||||||
// FIXME: Too much allocation here.
|
// FIXME: Too much allocation here.
|
||||||
let font_families = do my_style.font_family().map |family| {
|
let font_families = do my_style.font_family().map |family| {
|
||||||
|
@ -865,6 +873,30 @@ impl RenderBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let font_style_cached = match *self {
|
||||||
|
UnscannedTextRenderBoxClass(ref box) => {
|
||||||
|
match box.font_style {
|
||||||
|
Some(ref style) => Some(style.clone()),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
|
||||||
|
if font_style_cached.is_some() {
|
||||||
|
return font_style_cached.unwrap();
|
||||||
|
} else {
|
||||||
|
let font_style = get_font_style(self.nearest_ancestor_element());
|
||||||
|
match *self {
|
||||||
|
UnscannedTextRenderBoxClass(ref box) => {
|
||||||
|
box.font_style = Some(font_style.clone());
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
return font_style;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the text alignment of the computed style of the nearest ancestor-or-self `Element`
|
/// Returns the text alignment of the computed style of the nearest ancestor-or-self `Element`
|
||||||
/// node.
|
/// node.
|
||||||
pub fn text_align(&self) -> CSSTextAlign {
|
pub fn text_align(&self) -> CSSTextAlign {
|
||||||
|
@ -916,7 +948,29 @@ impl RenderBox {
|
||||||
text_decoration
|
text_decoration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get_propagated_text_decoration(self.nearest_ancestor_element())
|
|
||||||
|
let text_decoration_cached = match *self {
|
||||||
|
UnscannedTextRenderBoxClass(ref box) => {
|
||||||
|
match box.text_decoration {
|
||||||
|
Some(ref decoration) => Some(decoration.clone()),
|
||||||
|
None => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
|
||||||
|
if text_decoration_cached.is_some() {
|
||||||
|
return text_decoration_cached.unwrap();
|
||||||
|
} else {
|
||||||
|
let text_decoration = get_propagated_text_decoration(self.nearest_ancestor_element());
|
||||||
|
match *self {
|
||||||
|
UnscannedTextRenderBoxClass(ref box) => {
|
||||||
|
box.text_decoration = Some(text_decoration.clone());
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
return text_decoration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dumps this node, for debugging.
|
/// Dumps this node, for debugging.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue