Bug 1244049 - Part 3: Replace the type of nsCSSSelector::mPseudoType. r=dbaron
authorBoris Chiou <boris.chiou@gmail.com>
Wed, 17 Feb 2016 22:04:00 +0100
changeset 284733 1f67b24cbb75f685cde5a156adac09d532aab003
parent 284732 248497c0c18dea01a6b076483b9cd1f85621e2e8
child 284734 09b52ee5396030d49e946114c2cb7507645b8c96
push id30013
push usercbook@mozilla.com
push dateFri, 19 Feb 2016 11:02:40 +0000
treeherdermozilla-central@a87d6d52c1fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1244049
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1244049 - Part 3: Replace the type of nsCSSSelector::mPseudoType. r=dbaron
layout/style/StyleRule.cpp
layout/style/StyleRule.h
--- a/layout/style/StyleRule.cpp
+++ b/layout/style/StyleRule.cpp
@@ -309,36 +309,34 @@ nsCSSSelector::nsCSSSelector(void)
     mIDList(nullptr),
     mClassList(nullptr),
     mPseudoClassList(nullptr),
     mAttrList(nullptr),
     mNegations(nullptr),
     mNext(nullptr),
     mNameSpace(kNameSpaceID_Unknown),
     mOperator(0),
-    mPseudoType(static_cast<int16_t>(CSSPseudoElementType::NotPseudo))
+    mPseudoType(CSSPseudoElementType::NotPseudo)
 {
   MOZ_COUNT_CTOR(nsCSSSelector);
-  static_assert(static_cast<int16_t>(CSSPseudoElementType::MAX) < INT16_MAX,
-                "CSSPseudoElementType values overflow mPseudoType");
 }
 
 nsCSSSelector*
 nsCSSSelector::Clone(bool aDeepNext, bool aDeepNegations) const
 {
   nsCSSSelector *result = new nsCSSSelector();
   if (!result)
     return nullptr;
 
   result->mNameSpace = mNameSpace;
   result->mLowercaseTag = mLowercaseTag;
   result->mCasedTag = mCasedTag;
   result->mOperator = mOperator;
   result->mPseudoType = mPseudoType;
-  
+
   NS_IF_CLONE(mIDList);
   NS_IF_CLONE(mClassList);
   NS_IF_CLONE(mPseudoClassList);
   NS_IF_CLONE(mAttrList);
 
   // No need to worry about multiple levels of recursion since an
   // mNegations can't have an mNext.
   NS_ASSERTION(!mNegations || !mNegations->mNext,
--- a/layout/style/StyleRule.h
+++ b/layout/style/StyleRule.h
@@ -20,16 +20,17 @@
 #include "nsCSSPseudoClasses.h"
 #include "nsCSSPseudoElements.h"
 #include "nsIStyleRule.h"
 
 class nsIAtom;
 struct nsCSSSelectorList;
 
 namespace mozilla {
+enum class CSSPseudoElementType : uint8_t;
 class CSSStyleSheet;
 } // namespace mozilla
 
 struct nsAtomList {
 public:
   explicit nsAtomList(nsIAtom* aAtom);
   explicit nsAtomList(const nsString& aAtomValue);
   ~nsAtomList(void);
@@ -203,21 +204,19 @@ private:
   // selector).
   bool CanBeNamespaced(bool aIsNegated) const;
   // Calculate the specificity of this selector (not including its mNext
   // or its mNegations).
   int32_t CalcWeightWithoutNegations() const;
 
 public:
   // Get and set the selector's pseudo type
-  mozilla::CSSPseudoElementType PseudoType() const {
-    return static_cast<mozilla::CSSPseudoElementType>(mPseudoType);
-  }
+  mozilla::CSSPseudoElementType PseudoType() const { return mPseudoType; }
   void SetPseudoType(mozilla::CSSPseudoElementType aType) {
-    mPseudoType = static_cast<int16_t>(aType);
+    mPseudoType = aType;
   }
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
   // For case-sensitive documents, mLowercaseTag is the same as mCasedTag,
   // but in case-insensitive documents (HTML) mLowercaseTag is lowercase.
   // Also, for pseudo-elements mCasedTag will be null but mLowercaseTag
   // contains their name.
@@ -228,18 +227,19 @@ public:
   nsPseudoClassList* mPseudoClassList; // atom for the pseudo, string for
                                        // the argument to functional pseudos
   nsAttrSelector* mAttrList;
   nsCSSSelector*  mNegations;
   nsCSSSelector*  mNext;
   int32_t         mNameSpace;
   char16_t       mOperator;
 private:
-  // int16_t to make sure it packs well with mOperator
-  int16_t        mPseudoType;
+  // The underlying type of CSSPseudoElementType is uint8_t and
+  // it packs well with mOperator. (char16_t + uint8_t is less than 32bits.)
+  mozilla::CSSPseudoElementType mPseudoType;
 
   nsCSSSelector(const nsCSSSelector& aCopy) = delete;
   nsCSSSelector& operator=(const nsCSSSelector& aCopy) = delete;
 };
 
 /**
  * A selector list is the unit of selectors that each style rule has.
  * For example, "P B, H1 B { ... }" would be a selector list with two