Skip to content

Commit

Permalink
Deduplicate the loop in iterate_through_fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Feb 11, 2020
1 parent ef8c51c commit d353e08
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions components/layout_2020/flow/root.rs
Expand Up @@ -204,52 +204,44 @@ impl FragmentTreeRoot {
where
F: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{
fn do_iteration<M>(
fragment: &Fragment,
fn recur<M>(
fragments: &[Fragment],
containing_block: &PhysicalRect<Length>,
process_func: &mut M,
) -> bool
where
M: FnMut(&Fragment, &PhysicalRect<Length>) -> bool,
{
if !process_func(fragment, containing_block) {
return false;
}

match fragment {
Fragment::Box(fragment) => {
let new_containing_block = fragment
.content_rect
.to_physical(fragment.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
for child in &fragment.children {
if !do_iteration(child, &new_containing_block, process_func) {
for fragment in fragments {
if !process_func(fragment, containing_block) {
return false;
}

match fragment {
Fragment::Box(fragment) => {
let new_containing_block = fragment
.content_rect
.to_physical(fragment.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
if !recur(&fragment.children, &new_containing_block, process_func) {
return false;
}
}
},
Fragment::Anonymous(fragment) => {
let new_containing_block = fragment
.rect
.to_physical(fragment.mode, containing_block)
.translate(containing_block.origin.to_vector());
for child in &fragment.children {
if !do_iteration(child, &new_containing_block, process_func) {
},
Fragment::Anonymous(fragment) => {
let new_containing_block = fragment
.rect
.to_physical(fragment.mode, containing_block)
.translate(containing_block.origin.to_vector());
if !recur(&fragment.children, &new_containing_block, process_func) {
return false;
}
}
},
_ => {},
},
_ => {},
}
}

true
}

for child in &self.children {
if !do_iteration(child, &self.initial_containing_block, process_func) {
break;
}
}
recur(&self.children, &self.initial_containing_block, process_func);
}

pub fn get_content_box_for_node(&self, requested_node: OpaqueNode) -> Rect<Au> {
Expand Down

0 comments on commit d353e08

Please sign in to comment.