Bug 1384868: Simplify a bit RuleNodeCacheConditions. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 27 Jul 2017 03:07:06 +0200
changeset 420128 19d5f43ce7d087016c23cedc653d2ab7de9f02c7
parent 420127 5a192849567ed9c67fc099255525a1cfb54887e6
child 420129 fad5412d0735fa726c4c98c14d50cc1039f376f9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1384868
milestone56.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 1384868: Simplify a bit RuleNodeCacheConditions. r=heycam MozReview-Commit-ID: 62ac5XCGLVQ
layout/style/RuleNodeCacheConditions.cpp
layout/style/RuleNodeCacheConditions.h
--- a/layout/style/RuleNodeCacheConditions.cpp
+++ b/layout/style/RuleNodeCacheConditions.cpp
@@ -21,17 +21,17 @@ bool
 RuleNodeCacheConditions::Matches(nsStyleContext* aStyleContext) const
 {
   MOZ_ASSERT(Cacheable());
   if ((mBits & eHaveFontSize) &&
       mFontSize != aStyleContext->StyleFont()->mFont.size) {
     return false;
   }
   if ((mBits & eHaveWritingMode) &&
-      (GetWritingMode() != WritingMode(aStyleContext).GetBits())) {
+      (mWritingMode != WritingMode(aStyleContext).GetBits())) {
     return false;
   }
   return true;
 }
 
 #ifdef DEBUG
 void
 RuleNodeCacheConditions::List() const
@@ -41,13 +41,13 @@ RuleNodeCacheConditions::List() const
   if (mBits & eHaveFontSize) {
     printf("FontSize(%d)", mFontSize);
     first = false;
   }
   if (mBits & eHaveWritingMode) {
     if (!first) {
       printf(", ");
     }
-    printf("WritingMode(0x%x)", GetWritingMode());
+    printf("WritingMode(0x%x)", mWritingMode);
   }
   printf(" }");
 }
 #endif
--- a/layout/style/RuleNodeCacheConditions.h
+++ b/layout/style/RuleNodeCacheConditions.h
@@ -35,30 +35,42 @@ namespace mozilla {
  * certain common conditions.  For these structs, setting conditions
  * (SetFontSizeDependency, SetWritingModeDependency) instead causes the
  * struct to be stored, with the condition, in the rule tree.
  */
 class RuleNodeCacheConditions
 {
 public:
   RuleNodeCacheConditions()
-    : mFontSize(0), mBits(0) {}
+    : mFontSize(0)
+    , mBits(0)
+    , mWritingMode(0)
+  {}
+
   RuleNodeCacheConditions(const RuleNodeCacheConditions& aOther)
-    : mFontSize(aOther.mFontSize), mBits(aOther.mBits) {}
+    : mFontSize(aOther.mFontSize)
+    , mBits(aOther.mBits)
+    , mWritingMode(aOther.mWritingMode)
+  {}
+
   RuleNodeCacheConditions& operator=(const RuleNodeCacheConditions& aOther)
   {
     mFontSize = aOther.mFontSize;
     mBits = aOther.mBits;
+    mWritingMode = aOther.mWritingMode;
     return *this;
   }
+
   bool operator==(const RuleNodeCacheConditions& aOther) const
   {
     return mFontSize == aOther.mFontSize &&
-           mBits == aOther.mBits;
+           mBits == aOther.mBits &&
+           mWritingMode == aOther.mWritingMode;
   }
+
   bool operator!=(const RuleNodeCacheConditions& aOther) const
   {
     return !(*this == aOther);
   }
 
   bool Matches(nsStyleContext* aStyleContext) const;
 
   /**
@@ -80,19 +92,19 @@ public:
   /**
    * Record that the data being computed depend on the writing mode of
    * the element for which they are being computed, which in turn
    * depends on its 'writing-mode', 'direction', and 'text-orientation'
    * properties.
    */
   void SetWritingModeDependency(uint8_t aWritingMode)
   {
-    MOZ_ASSERT(!(mBits & eHaveWritingMode) || GetWritingMode() == aWritingMode);
-    mBits |= (static_cast<uint64_t>(aWritingMode) << eWritingModeShift) |
-             eHaveWritingMode;
+    MOZ_ASSERT(!(mBits & eHaveWritingMode) || mWritingMode == aWritingMode);
+    mWritingMode = aWritingMode;
+    mBits |= eHaveWritingMode;
   }
 
   void SetUncacheable()
   {
     mBits |= eUncacheable;
   }
 
   void Clear()
@@ -102,55 +114,43 @@ public:
 
   bool Cacheable() const
   {
     return !(mBits & eUncacheable);
   }
 
   bool CacheableWithDependencies() const
   {
-    return !(mBits & eUncacheable) &&
-           (mBits & eHaveBitsMask) != 0;
+    return Cacheable() && mBits;
   }
 
   bool CacheableWithoutDependencies() const
   {
     // We're not uncacheable and we have don't have a font-size or
     // writing mode value.
-    return (mBits & eHaveBitsMask) == 0;
+    return mBits == 0;
   }
 
 #ifdef DEBUG
   void List() const;
 #endif
 
 private:
   enum {
-    eUncacheable      = 0x0001,
-    eHaveFontSize     = 0x0002,
-    eHaveWritingMode  = 0x0004,
-    eHaveBitsMask     = 0x00ff,
-    eWritingModeMask  = 0xff00,
-    eWritingModeShift = 8,
+    eUncacheable      = 1 << 0,
+    eHaveFontSize     = 1 << 1,
+    eHaveWritingMode  = 1 << 2,
   };
 
-  uint8_t GetWritingMode() const
-  {
-    return static_cast<uint8_t>(
-        (mBits & eWritingModeMask) >> eWritingModeShift);
-  }
-
   // The font size from which em units are derived.
   nscoord mFontSize;
 
   // Values in mBits:
   //   bit 0:      are we set to "uncacheable"?
   //   bit 1:      do we have a font size value?
   //   bit 2:      do we have a writing mode value?
-  //   bits 3-7:   unused
-  //   bits 8-15:  writing mode (uint8_t)
-  //   bits 16-31: unused
-  uint32_t mBits;
+  uint8_t mBits;
+  uint8_t mWritingMode;
 };
 
 } // namespace mozilla
 
 #endif // !defined(RuleNodeCacheConditions_h_)