From 344d53bd294582453376e47443826d2922fd0742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 28 Aug 2017 20:12:35 +0200 Subject: [PATCH] style: Avoid scanning the longhand id twice in the fast path of PropertyDeclarationBlock::push_common. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the overhead of this function much lower according to `perf`. And in general makes sense, removing overhead from the fast path. MozReview-Commit-ID: 4dJRap9dxNG Signed-off-by: Emilio Cobos Álvarez --- components/style/properties/declaration_block.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 54ffa4621fd..ce55eae6e98 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -402,12 +402,14 @@ impl PropertyDeclarationBlock { importance: Importance, overwrite_more_important_and_reuse_slot: bool ) -> bool { - let definitely_new = if let PropertyDeclarationId::Longhand(id) = declaration.id() { - !self.longhands.contains(id) - } else { - false // For custom properties, always scan + let longhand_id = match declaration.id() { + PropertyDeclarationId::Longhand(id) => Some(id), + PropertyDeclarationId::Custom(..) => None, }; + let definitely_new = longhand_id.map_or(false, |id| { + !self.longhands.contains(id) + }); if !definitely_new { let mut index_to_remove = None; @@ -449,7 +451,7 @@ impl PropertyDeclarationBlock { } } - if let PropertyDeclarationId::Longhand(id) = declaration.id() { + if let Some(id) = longhand_id { self.longhands.insert(id); } self.declarations.push((declaration, importance));