Bug 525608 part 8. Reorder the cases in AddRule in order of likelihood. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 10 Dec 2009 14:36:06 -0800
changeset 35543 2b1ea61744277a1cf93ae9b97dec422d466dc9cc
parent 35542 ab94482457450dd1ef56408a0e60ffd5a2cd37f5
child 35544 f0c4d36607ac56a41b8136f1c9cc8dd256100bb1
push id10631
push userbzbarsky@mozilla.com
push dateThu, 10 Dec 2009 22:48:24 +0000
treeherdermozilla-central@08b48be6951b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs525608
milestone1.9.3a1pre
Bug 525608 part 8. Reorder the cases in AddRule in order of likelihood. r=dbaron
layout/style/nsCSSRuleProcessor.cpp
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -2363,17 +2363,19 @@ PRBool IsStateSelector(nsCSSSelector& aS
 
 static PRBool
 AddRule(RuleValue* aRuleInfo, RuleCascadeData* aCascade)
 {
   RuleCascadeData * const cascade = aCascade;
 
   // Build the rule hash.
   nsCSSPseudoElements::Type pseudoType = aRuleInfo->mSelector->PseudoType();
-  if (pseudoType < nsCSSPseudoElements::ePseudo_PseudoElementCount) {
+  if (NS_LIKELY(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement)) {
+    cascade->mRuleHash.PrependRule(aRuleInfo);
+  } else if (pseudoType < nsCSSPseudoElements::ePseudo_PseudoElementCount) {
     RuleHash*& ruleHash = cascade->mPseudoElementRuleHashes[pseudoType];
     if (!ruleHash) {
       ruleHash = new RuleHash(cascade->mQuirksMode);
       if (!ruleHash) {
         // Out of memory; give up
         return PR_FALSE;
       }
     }
@@ -2394,30 +2396,28 @@ AddRule(RuleValue* aRuleInfo, RuleCascad
                  aRuleInfo->mSelector->mNameSpace == kNameSpaceID_Unknown,
                  "Parser messed up with anon box selector");
 
     // Index doesn't matter here, since we'll just be walking these
     // rules in order; just pass 0.
     DoPrependRuleToTagTable(&cascade->mAnonBoxRules,
                             aRuleInfo->mSelector->mLowercaseTag,
                             aRuleInfo, 0);
-  }
+  } else {
 #ifdef MOZ_XUL
-  else if (pseudoType == nsCSSPseudoElements::ePseudo_XULTree) {
+    NS_ASSERTION(pseudoType == nsCSSPseudoElements::ePseudo_XULTree,
+                 "Unexpected pseudo type");
     // Index doesn't matter here, since we'll just be walking these
     // rules in order; just pass 0.
     DoPrependRuleToTagTable(&cascade->mXULTreeRules,
                             aRuleInfo->mSelector->mLowercaseTag,
                             aRuleInfo, 0);
-  }
+#else
+    NS_NOTREACHED("Unexpected pseudo type");
 #endif
-  else {
-    NS_ASSERTION(pseudoType == nsCSSPseudoElements::ePseudo_NotPseudoElement,
-                 "Unexpected pseudoType");
-    cascade->mRuleHash.PrependRule(aRuleInfo);
   }
 
   nsTArray<nsCSSSelector*>* stateArray = &cascade->mStateSelectors;
   nsTArray<nsCSSSelector*>* classArray = &cascade->mClassSelectors;
   nsTArray<nsCSSSelector*>* idArray = &cascade->mIDSelectors;
   
   for (nsCSSSelector* selector = aRuleInfo->mSelector;
            selector; selector = selector->mNext) {