From 510bcc6186eb7c6cb1ce480ae209a898bb35c965 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Mon, 3 Apr 2017 11:39:10 +0200 Subject: [PATCH] Remove a memory allocation (`iter.collect::>()`) in `cascade()` This vector was there to pre-acquire locks and give all declarations the same lifetime (which is necessary for custom properties cascading). https://github.com/servo/servo/pull/16014 introduce a guard to a shared pre-acquired lock, making this vector unnecessary. --- .../style/properties/properties.mako.rs | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index fb61e231dd7..13565f00f41 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1976,24 +1976,25 @@ pub fn cascade(device: &Device, } }; - // Hold locks until after the apply_declarations() call returns. - // Use filter_map because the root node has no style source. - let declaration_blocks = rule_node.self_and_ancestors().filter_map(|node| { - let guard = node.cascade_level().guard(guards); - node.style_source().map(|source| (source.read(guard), node.importance())) - }).collect::>(); let iter_declarations = || { - declaration_blocks.iter().flat_map(|&(ref source, source_importance)| { - source.declarations().iter() - // Yield declarations later in source order (with more precedence) first. - .rev() - .filter_map(move |&(ref declaration, declaration_importance)| { - if declaration_importance == source_importance { - Some(declaration) - } else { - None - } - }) + rule_node.self_and_ancestors().flat_map(|node| { + let declarations = match node.style_source() { + Some(source) => source.read(node.cascade_level().guard(guards)).declarations(), + // The root node has no style source. + None => &[] + }; + let node_importance = node.importance(); + declarations + .iter() + // Yield declarations later in source order (with more precedence) first. + .rev() + .filter_map(move |&(ref declaration, declaration_importance)| { + if declaration_importance == node_importance { + Some(declaration) + } else { + None + } + }) }) }; apply_declarations(device,