diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-15 03:14:08 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-06-15 03:14:08 +0200 |
commit | b41f741f5bf0e97fe2fb791bca07f0ffd6d66ba3 (patch) | |
tree | 4236a351e738671a336652fbe8d811cf51b34579 | |
parent | b741df35253e63d80151b97c1e442f92614baaf4 (diff) | |
download | servo-b41f741f5bf0e97fe2fb791bca07f0ffd6d66ba3.tar.gz servo-b41f741f5bf0e97fe2fb791bca07f0ffd6d66ba3.zip |
style: Avoid some branches in common RuleIterator::next cases.
I saw this function appear in the profiles at #17329.
It was under set_device, which isn't a Stylo path, but probably worth there
anyway.
This reduces the reported overhead of RulesIterator::next in perf from ~8% to
0.46%
-rw-r--r-- | components/style/stylesheets/rules_iterator.rs | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/components/style/stylesheets/rules_iterator.rs b/components/style/stylesheets/rules_iterator.rs index cbcaf9e0123..05dd2e71676 100644 --- a/components/style/stylesheets/rules_iterator.rs +++ b/components/style/stylesheets/rules_iterator.rs @@ -68,8 +68,7 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> } let rule; - let sub_iter; - { + let sub_iter = { let mut nested_iter = self.stack.last_mut().unwrap(); rule = match nested_iter.next() { Some(r) => r, @@ -79,7 +78,16 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> } }; - sub_iter = match *rule { + match *rule { + CssRule::Namespace(_) | + CssRule::Style(_) | + CssRule::FontFace(_) | + CssRule::CounterStyle(_) | + CssRule::Viewport(_) | + CssRule::Keyframes(_) | + CssRule::Page(_) => { + return Some(rule) + }, CssRule::Import(ref import_rule) => { let import_rule = import_rule.read_with(self.guard); if !C::process_import(self.guard, @@ -88,7 +96,7 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> import_rule) { continue; } - Some(import_rule.stylesheet.rules.read_with(self.guard).0.iter()) + import_rule.stylesheet.rules.read_with(self.guard).0.iter() } CssRule::Document(ref doc_rule) => { let doc_rule = doc_rule.read_with(self.guard); @@ -98,7 +106,7 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> doc_rule) { continue; } - Some(doc_rule.rules.read_with(self.guard).0.iter()) + doc_rule.rules.read_with(self.guard).0.iter() } CssRule::Media(ref lock) => { let media_rule = lock.read_with(self.guard); @@ -108,7 +116,7 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> media_rule) { continue; } - Some(media_rule.rules.read_with(self.guard).0.iter()) + media_rule.rules.read_with(self.guard).0.iter() } CssRule::Supports(ref lock) => { let supports_rule = lock.read_with(self.guard); @@ -118,22 +126,12 @@ impl<'a, 'b, C> Iterator for RulesIterator<'a, 'b, C> supports_rule) { continue; } - Some(supports_rule.rules.read_with(self.guard).0.iter()) + supports_rule.rules.read_with(self.guard).0.iter() } - CssRule::Namespace(_) | - CssRule::Style(_) | - CssRule::FontFace(_) | - CssRule::CounterStyle(_) | - CssRule::Viewport(_) | - CssRule::Keyframes(_) | - CssRule::Page(_) => None, - }; - } - - if let Some(sub_iter) = sub_iter { - self.stack.push(sub_iter); - } + } + }; + self.stack.push(sub_iter); return Some(rule); } |