From 05cf52cb0b2e29ff886c9835e631fc89d541e7f5 Mon Sep 17 00:00:00 2001 From: Pu Xingyu Date: Wed, 20 Jul 2016 16:55:44 +0800 Subject: [PATCH] Filter abs-pos children and sort by 'order' field As the flexbox spec change in May 2016, the absolutely positioned children painting order no longer follow the `order` property, thus we can simply filter them out. Also sort items by the order field of 'FlexItem', no longer do two vtable lookups in each compare. --- components/layout/flex.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/components/layout/flex.rs b/components/layout/flex.rs index 15685e7b69d..8ec46bf2bd7 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -712,19 +712,14 @@ impl Flow for FlexFlow { // Flexbox Section 9.0: Generate anonymous flex items: // This part was handled in the flow constructor. - // Flexbox Section 9.1: Re-order the flex items (and any absolutely positioned flex - // container children) according to their order. - - let mut items = self.block_flow.base.children.iter_flow_ref_mut().map(|flow| { - FlexItem::new(flow.clone()) - }).collect::>(); - - items.sort_by(|item1, item2| { - item1.flow.as_block().fragment.style.get_position().order.cmp( - &item2.flow.as_block().fragment.style.get_position().order - ) - }); + // Flexbox Section 9.1: Re-order flex items according to their order. + // FIXME(stshine): This should be done during flow construction. + let mut items = self.block_flow.base.children.iter_flow_ref_mut() + .filter(|flow| !flow.as_block().base.flags.contains(IS_ABSOLUTELY_POSITIONED)) + .map(|flow| FlexItem::new(flow.clone())) + .collect::>(); + items.sort_by_key(|item| item.order); self.items = items; match self.main_mode {