From c0350e77394be91456b475e7a72ab6b364544aa6 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Oct 2012 14:27:40 -0700 Subject: [PATCH] Change StyleMethods::style to return a region pointer instead of copying the style object --- src/servo/css/styles.rs | 11 ++++++----- src/servo/layout/box.rs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 8f5737e2b26..7aade2f0b97 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -105,7 +105,7 @@ fn empty_style_for_node_kind(kind: &NodeKind) -> SpecifiedStyle { trait StyleMethods { fn initialize_layout_data() -> Option<@LayoutData>; - fn style() -> SpecifiedStyle; + fn style() -> &self/SpecifiedStyle; fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>); fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx); } @@ -129,15 +129,16 @@ impl Node : StyleMethods { } /** - * Returns the computed style for the given node. If CSS selector + * Provides the computed style for the given node. If CSS selector * matching has not yet been performed, fails. + * FIXME: This isn't completely memory safe since the style is + * stored in a box that can be overwritten */ - fn style() -> SpecifiedStyle { + fn style() -> &self/SpecifiedStyle { if !self.has_aux() { fail ~"get_style() called on a node without a style!"; } - // TODO: return a safe reference; don't copy! - return copy *self.aux(|x| copy *x).style; + unsafe { &*self.aux( |x| ptr::to_unsafe_ptr(&*x.style) ) } } /** diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index cc9f87ffb35..457e70e0a0b 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -457,7 +457,7 @@ impl RenderBox : RenderBoxMethods { fn add_border_to_list(list: &mut DisplayList, abs_bounds: &Rect) { let style = self.d().node.style(); match style.border_width { - Specified(Px(px)) => { + Specified(Px(copy px)) => { // If there's a border, let's try to display *something* let border_width = au::from_frac_px(px); let abs_bounds = Rect {