Bug 1338086 - Remove useless else blocks in order to reduce complexity in layout/ r?heycam draft
authorSylvestre Ledru <sledru@mozilla.com>
Thu, 09 Feb 2017 11:48:59 +0100
changeset 484425 b5756bed7a5ce649f892195ec85692cc48b7cad5
parent 484424 c73ac810dc1ac29a7703b15a730220cf163373e1
child 484426 e9bb472aeff706389eb71d1fdce0d5c5f13e9a55
push id45470
push userbmo:sledru@mozilla.com
push dateWed, 15 Feb 2017 08:57:47 +0000
reviewersheycam
bugs1338086
milestone54.0a1
Bug 1338086 - Remove useless else blocks in order to reduce complexity in layout/ r?heycam MozReview-Commit-ID: 9s4z7bYXisU
layout/style/nsCSSRuleProcessor.cpp
--- a/layout/style/nsCSSRuleProcessor.cpp
+++ b/layout/style/nsCSSRuleProcessor.cpp
@@ -2128,85 +2128,84 @@ static bool SelectorMatches(Element* aEl
   }
 
   bool result = true;
   if (aSelector->mAttrList) {
     // test for attribute match
     if (!aElement->HasAttrs()) {
       // if no attributes on the content, no match
       return false;
-    } else {
-      result = true;
-      nsAttrSelector* attr = aSelector->mAttrList;
-      nsIAtom* matchAttribute;
-
-      do {
-        bool isHTML =
-          (aTreeMatchContext.mIsHTMLDocument && aElement->IsHTMLElement());
-        matchAttribute = isHTML ? attr->mLowercaseAttr : attr->mCasedAttr;
-        if (attr->mNameSpace == kNameSpaceID_Unknown) {
-          // Attr selector with a wildcard namespace.  We have to examine all
-          // the attributes on our content node....  This sort of selector is
-          // essentially a boolean OR, over all namespaces, of equivalent attr
-          // selectors with those namespaces.  So to evaluate whether it
-          // matches, evaluate for each namespace (the only namespaces that
-          // have a chance at matching, of course, are ones that the element
-          // actually has attributes in), short-circuiting if we ever match.
-          result = false;
-          const nsAttrName* attrName;
-          for (uint32_t i = 0; (attrName = aElement->GetAttrNameAt(i)); ++i) {
-            if (attrName->LocalName() != matchAttribute) {
-              continue;
-            }
-            if (attr->mFunction == NS_ATTR_FUNC_SET) {
-              result = true;
-            } else {
-              nsAutoString value;
+    }
+    result = true;
+    nsAttrSelector* attr = aSelector->mAttrList;
+    nsIAtom* matchAttribute;
+
+    do {
+      bool isHTML =
+        (aTreeMatchContext.mIsHTMLDocument && aElement->IsHTMLElement());
+      matchAttribute = isHTML ? attr->mLowercaseAttr : attr->mCasedAttr;
+      if (attr->mNameSpace == kNameSpaceID_Unknown) {
+        // Attr selector with a wildcard namespace.  We have to examine all
+        // the attributes on our content node....  This sort of selector is
+        // essentially a boolean OR, over all namespaces, of equivalent attr
+        // selectors with those namespaces.  So to evaluate whether it
+        // matches, evaluate for each namespace (the only namespaces that
+        // have a chance at matching, of course, are ones that the element
+        // actually has attributes in), short-circuiting if we ever match.
+        result = false;
+        const nsAttrName* attrName;
+        for (uint32_t i = 0; (attrName = aElement->GetAttrNameAt(i)); ++i) {
+          if (attrName->LocalName() != matchAttribute) {
+            continue;
+          }
+          if (attr->mFunction == NS_ATTR_FUNC_SET) {
+            result = true;
+          } else {
+            nsAutoString value;
 #ifdef DEBUG
-              bool hasAttr =
+            bool hasAttr =
 #endif
-                aElement->GetAttr(attrName->NamespaceID(),
-                                  attrName->LocalName(), value);
-              NS_ASSERTION(hasAttr, "GetAttrNameAt lied");
-              result = AttrMatchesValue(attr, value, isHTML);
-            }
-
-            // At this point |result| has been set by us
-            // explicitly in this loop.  If it's false, we may still match
-            // -- the content may have another attribute with the same name but
-            // in a different namespace.  But if it's true, we are done (we
-            // can short-circuit the boolean OR described above).
-            if (result) {
-              break;
-            }
+              aElement->GetAttr(attrName->NamespaceID(),
+                                attrName->LocalName(), value);
+            NS_ASSERTION(hasAttr, "GetAttrNameAt lied");
+            result = AttrMatchesValue(attr, value, isHTML);
+          }
+
+          // At this point |result| has been set by us
+          // explicitly in this loop.  If it's false, we may still match
+          // -- the content may have another attribute with the same name but
+          // in a different namespace.  But if it's true, we are done (we
+          // can short-circuit the boolean OR described above).
+          if (result) {
+            break;
           }
         }
-        else if (attr->mFunction == NS_ATTR_FUNC_EQUALS) {
-          result =
-            aElement->
-              AttrValueIs(attr->mNameSpace, matchAttribute, attr->mValue,
-                          attr->IsValueCaseSensitive(isHTML) ? eCaseMatters
-                                                             : eIgnoreCase);
-        }
-        else if (!aElement->HasAttr(attr->mNameSpace, matchAttribute)) {
-          result = false;
-        }
-        else if (attr->mFunction != NS_ATTR_FUNC_SET) {
-          nsAutoString value;
+      }
+      else if (attr->mFunction == NS_ATTR_FUNC_EQUALS) {
+        result =
+          aElement->
+          AttrValueIs(attr->mNameSpace, matchAttribute, attr->mValue,
+                      attr->IsValueCaseSensitive(isHTML) ? eCaseMatters
+                                                         : eIgnoreCase);
+      }
+      else if (!aElement->HasAttr(attr->mNameSpace, matchAttribute)) {
+        result = false;
+      }
+      else if (attr->mFunction != NS_ATTR_FUNC_SET) {
+        nsAutoString value;
 #ifdef DEBUG
-          bool hasAttr =
+        bool hasAttr =
 #endif
-              aElement->GetAttr(attr->mNameSpace, matchAttribute, value);
-          NS_ASSERTION(hasAttr, "HasAttr lied");
-          result = AttrMatchesValue(attr, value, isHTML);
-        }
-        
-        attr = attr->mNext;
-      } while (attr && result);
-    }
+          aElement->GetAttr(attr->mNameSpace, matchAttribute, value);
+        NS_ASSERTION(hasAttr, "HasAttr lied");
+        result = AttrMatchesValue(attr, value, isHTML);
+      }
+
+      attr = attr->mNext;
+    } while (attr && result);
   }
 
   // apply SelectorMatches to the negated selectors in the chain
   if (!isNegated) {
     for (nsCSSSelector *negation = aSelector->mNegations;
          result && negation; negation = negation->mNegations) {
       bool dependence = false;
       result = !SelectorMatches(aElement, negation, aNodeMatchContext,