From 4381107c217bde65bba1f14b1543a614c2ea7d09 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 23 Jun 2016 13:52:26 +0200 Subject: [PATCH] Make the STYLE_BLOOM global private. --- components/layout/traversal.rs | 30 ++------------------------ components/style/traversal.rs | 39 ++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index 9888db994c0..5db766f68b5 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -13,16 +13,12 @@ use gfx::display_list::OpaqueNode; use script_layout_interface::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RestyleDamage}; use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use std::mem; -use style::context::StyleContext; use style::dom::TNode; -use style::matching::MatchMethods; use style::properties::ServoComputedValues; use style::selector_impl::ServoSelectorImpl; use style::servo::SharedStyleContext; -use style::traversal::{DomTraversalContext, STYLE_BLOOM}; -use style::traversal::{put_thread_local_bloom_filter, recalc_style_at}; +use style::traversal::{DomTraversalContext, remove_from_bloom_filter, recalc_style_at}; use util::opts; -use util::tid::tid; use wrapper::{LayoutNodeLayoutData, ThreadSafeLayoutNodeHelpers}; pub struct RecalcStyleAndConstructFlows<'lc> { @@ -122,29 +118,7 @@ fn construct_flows_at<'a, N: LayoutNode>(context: &'a LayoutContext<'a>, root: O node.set_dirty_descendants(false); } - let unsafe_layout_node = node.to_unsafe(); - - let (mut bf, old_node, old_generation) = - STYLE_BLOOM.with(|style_bloom| { - mem::replace(&mut *style_bloom.borrow_mut(), None) - .expect("The bloom filter should have been set by style recalc.") - }); - - assert_eq!(old_node, unsafe_layout_node); - assert_eq!(old_generation, context.shared_context().generation); - - match node.layout_parent_node(root) { - None => { - debug!("[{}] - {:X}, and deleting BF.", tid(), unsafe_layout_node.0); - // If this is the reflow root, eat the thread-local bloom filter. - } - Some(parent) => { - // Otherwise, put it back, but remove this node. - node.remove_from_bloom_filter(&mut *bf); - let unsafe_parent = parent.to_unsafe(); - put_thread_local_bloom_filter(bf, &unsafe_parent, &context.shared_context()); - }, - }; + remove_from_bloom_filter(context, root, node); } /// The bubble-inline-sizes traversal, the first part of layout computation. This computes diff --git a/components/style/traversal.rs b/components/style/traversal.rs index d383cc5f706..331e368e584 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -37,7 +37,7 @@ pub type Generation = u32; /// will no longer be the for the parent of the node we're currently on. When /// this happens, the thread local bloom filter will be thrown away and rebuilt. thread_local!( - pub static STYLE_BLOOM: RefCell, UnsafeNode, Generation)>> = RefCell::new(None)); + static STYLE_BLOOM: RefCell, UnsafeNode, Generation)>> = RefCell::new(None)); /// Returns the thread local bloom filter. /// @@ -79,9 +79,9 @@ fn take_thread_local_bloom_filter(parent_node: Option< }) } -pub fn put_thread_local_bloom_filter(bf: Box, - unsafe_node: &UnsafeNode, - context: &SharedStyleContext) { +fn put_thread_local_bloom_filter(bf: Box, + unsafe_node: &UnsafeNode, + context: &SharedStyleContext) { STYLE_BLOOM.with(move |style_bloom| { assert!(style_bloom.borrow().is_none(), "Putting into a never-taken thread-local bloom filter"); @@ -108,6 +108,37 @@ fn insert_ancestors_into_bloom_filter(bf: &mut Box, debug!("[{}] Inserted {} ancestors.", tid(), ancestors); } +pub fn remove_from_bloom_filter<'a, N, C, Impl>(context: &C, root: OpaqueNode, node: N) + where N: TNode, + Impl: SelectorImplExt + 'a, + C: StyleContext<'a, Impl> +{ + let unsafe_layout_node = node.to_unsafe(); + + let (mut bf, old_node, old_generation) = + STYLE_BLOOM.with(|style_bloom| { + style_bloom.borrow_mut() + .take() + .expect("The bloom filter should have been set by style recalc.") + }); + + assert_eq!(old_node, unsafe_layout_node); + assert_eq!(old_generation, context.shared_context().generation); + + match node.layout_parent_node(root) { + None => { + debug!("[{}] - {:X}, and deleting BF.", tid(), unsafe_layout_node.0); + // If this is the reflow root, eat the thread-local bloom filter. + } + Some(parent) => { + // Otherwise, put it back, but remove this node. + node.remove_from_bloom_filter(&mut *bf); + let unsafe_parent = parent.to_unsafe(); + put_thread_local_bloom_filter(bf, &unsafe_parent, &context.shared_context()); + }, + }; +} + pub trait DomTraversalContext { type SharedContext: Sync + 'static; fn new<'a>(&'a Self::SharedContext, OpaqueNode) -> Self;