gecko-dev/servo/components/style/sequential.rs
Bobby Holley 8eb98de31a servo: Merge #14642 - Use Scoped TLS in the style system and eliminate UnsafeNode usage in the StyleSharingCandidateCache (from bholley:scoped_tls); r=emilio
See the discussion in https://bugzilla.mozilla.org/show_bug.cgi?id=1323372

@emilio Please review, but don't merge yet until we get the upstream changes into Rayon.

CC @SimonSapin @heycam @upsuper @Manishearth @pcwalton @nikomatsakis

Source-Repo: https://github.com/servo/servo
Source-Revision: 8fd8d6161426af386c0dfd3d13968a409474eb16
2016-12-21 11:11:12 -08:00

56 lines
1.9 KiB
Rust

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! Implements sequential traversal over the DOM tree.
use dom::{TElement, TNode};
use traversal::{DomTraversal, PerLevelTraversalData, PreTraverseToken};
pub fn traverse_dom<N, D>(traversal: &D,
root: N::ConcreteElement,
token: PreTraverseToken)
where N: TNode,
D: DomTraversal<N>
{
debug_assert!(token.should_traverse());
fn doit<N, D>(traversal: &D, traversal_data: &mut PerLevelTraversalData,
thread_local: &mut D::ThreadLocalContext, node: N)
where N: TNode,
D: DomTraversal<N>
{
traversal.process_preorder(traversal_data, thread_local, node);
if let Some(el) = node.as_element() {
if let Some(ref mut depth) = traversal_data.current_dom_depth {
*depth += 1;
}
D::traverse_children(el, |kid| doit(traversal, traversal_data, thread_local, kid));
if let Some(ref mut depth) = traversal_data.current_dom_depth {
*depth -= 1;
}
}
if D::needs_postorder_traversal() {
traversal.process_postorder(thread_local, node);
}
}
let mut traversal_data = PerLevelTraversalData {
current_dom_depth: None,
};
let mut tlc = traversal.create_thread_local_context();
if token.traverse_unstyled_children_only() {
for kid in root.as_node().children() {
if kid.as_element().map_or(false, |el| el.get_data().is_none()) {
doit(traversal, &mut traversal_data, &mut tlc, kid);
}
}
} else {
doit(traversal, &mut traversal_data, &mut tlc, root.as_node());
}
}