Bug 1429529 - Rename CachedAnonBoxStyles to CachedInheritingStyles. r=emilio
authorBobby Holley <bobbyholley@gmail.com>
Wed, 10 Jan 2018 10:57:12 -0800
changeset 453183 85f9b85ae324a57ed28c1c268d96bd80eefd17da
parent 453182 a8e7f7f28f7e1010039927ac6b87c1647338f89c
child 453184 ea45022c163ec2fd9a2ce9c5444d1593b9c8aa9d
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemilio
bugs1429529
milestone59.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 1429529 - Rename CachedAnonBoxStyles to CachedInheritingStyles. r=emilio MozReview-Commit-ID: xgZbalAJ5x
layout/style/CachedAnonBoxStyles.cpp
layout/style/CachedAnonBoxStyles.h
layout/style/CachedInheritingStyles.cpp
layout/style/CachedInheritingStyles.h
layout/style/ServoStyleContext.h
layout/style/moz.build
deleted file mode 100644
--- a/layout/style/CachedAnonBoxStyles.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsIMemoryReporter.h"
-#include "mozilla/CachedAnonBoxStyles.h"
-#include "mozilla/ServoStyleContext.h"
-
-namespace mozilla {
-
-void
-CachedAnonBoxStyles::Insert(ServoStyleContext* aStyle)
-{
-  MOZ_ASSERT(aStyle);
-  MOZ_ASSERT(aStyle->IsInheritingAnonBox());
-
-  if (IsEmpty()) {
-    RefPtr<ServoStyleContext> s = aStyle;
-    mBits = reinterpret_cast<uintptr_t>(s.forget().take());
-    MOZ_ASSERT(!IsEmpty() && !IsIndirect());
-  } else if (IsIndirect()) {
-    AsIndirect()->AppendElement(aStyle);
-  } else {
-    IndirectCache* cache = new IndirectCache();
-    cache->AppendElement(dont_AddRef(AsDirect()));
-    cache->AppendElement(aStyle);
-    mBits = reinterpret_cast<uintptr_t>(cache) | 1;
-    MOZ_ASSERT(IsIndirect());
-  }
-}
-
-ServoStyleContext*
-CachedAnonBoxStyles::Lookup(nsAtom* aAnonBox) const
-{
-  MOZ_ASSERT(nsCSSAnonBoxes::IsInheritingAnonBox(aAnonBox));
-  if (IsIndirect()) {
-    for (auto& style : *AsIndirect()) {
-      if (style->GetPseudo() == aAnonBox) {
-        return style;
-      }
-    }
-
-    return nullptr;
-  }
-
-  ServoStyleContext* direct = AsDirect();
-  return direct && direct->GetPseudo() == aAnonBox ? direct : nullptr;
-}
-
-void
-CachedAnonBoxStyles::AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const
-{
-  if (IsIndirect()) {
-    for (auto& style : *AsIndirect()) {
-      if (!aSizes.mState.HaveSeenPtr(style)) {
-        style->AddSizeOfIncludingThis(aSizes, aCVsSize);
-      }
-    }
-
-    return;
-  }
-
-  ServoStyleContext* direct = AsDirect();
-  if (direct && !aSizes.mState.HaveSeenPtr(direct)) {
-    direct->AddSizeOfIncludingThis(aSizes, aCVsSize);
-  }
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/layout/style/CachedAnonBoxStyles.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef mozilla_CachedAnonBoxStyles_h
-#define mozilla_CachedAnonBoxStyles_h
-
-#include "nsAtom.h"
-#include "nsTArray.h"
-
-class nsWindowSizes;
-
-namespace mozilla {
-
-class ServoStyleContext;
-
-// Cache of anonymous box styles that inherit from a given style.
-//
-// To minimize memory footprint, the cache is word-sized with a tagged pointer
-// If there is only one entry, it's stored inline. If there are more, they're
-// stored in an out-of-line buffer. See bug 1429126 comment 0 and comment 1 for
-// the measurements and rationale that influenced the design.
-class CachedAnonBoxStyles
-{
-public:
-  void Insert(ServoStyleContext* aStyle);
-  ServoStyleContext* Lookup(nsAtom* aAnonBox) const;
-
-  CachedAnonBoxStyles() : mBits(0) {}
-  ~CachedAnonBoxStyles()
-  {
-    if (IsIndirect()) {
-      delete AsIndirect();
-    } else if (!IsEmpty()) {
-      RefPtr<ServoStyleContext> ref = dont_AddRef(AsDirect());
-    }
-  }
-
-  void AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const;
-
-private:
-  // See bug 1429126 comment 1 for the choice of four here.
-  typedef AutoTArray<RefPtr<ServoStyleContext>, 4> IndirectCache;
-
-  bool IsEmpty() const { return !mBits; }
-  bool IsIndirect() const { return (mBits & 1); }
-
-  ServoStyleContext* AsDirect() const
-  {
-    MOZ_ASSERT(!IsIndirect());
-    return reinterpret_cast<ServoStyleContext*>(mBits);
-  }
-
-  IndirectCache* AsIndirect() const
-  {
-    MOZ_ASSERT(IsIndirect());
-    return reinterpret_cast<IndirectCache*>(mBits & ~1);
-  }
-
-  uintptr_t mBits;
-};
-
-} // namespace mozilla
-
-#endif // mozilla_CachedAnonBoxStyles_h
new file mode 100644
--- /dev/null
+++ b/layout/style/CachedInheritingStyles.cpp
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nsIMemoryReporter.h"
+#include "mozilla/CachedInheritingStyles.h"
+#include "mozilla/ServoStyleContext.h"
+
+namespace mozilla {
+
+void
+CachedInheritingStyles::Insert(ServoStyleContext* aStyle)
+{
+  MOZ_ASSERT(aStyle);
+  MOZ_ASSERT(aStyle->IsInheritingAnonBox());
+
+  if (IsEmpty()) {
+    RefPtr<ServoStyleContext> s = aStyle;
+    mBits = reinterpret_cast<uintptr_t>(s.forget().take());
+    MOZ_ASSERT(!IsEmpty() && !IsIndirect());
+  } else if (IsIndirect()) {
+    AsIndirect()->AppendElement(aStyle);
+  } else {
+    IndirectCache* cache = new IndirectCache();
+    cache->AppendElement(dont_AddRef(AsDirect()));
+    cache->AppendElement(aStyle);
+    mBits = reinterpret_cast<uintptr_t>(cache) | 1;
+    MOZ_ASSERT(IsIndirect());
+  }
+}
+
+ServoStyleContext*
+CachedInheritingStyles::Lookup(nsAtom* aPseudoTag) const
+{
+  MOZ_ASSERT(nsCSSAnonBoxes::IsInheritingAnonBox(aPseudoTag));
+  if (IsIndirect()) {
+    for (auto& style : *AsIndirect()) {
+      if (style->GetPseudo() == aPseudoTag) {
+        return style;
+      }
+    }
+
+    return nullptr;
+  }
+
+  ServoStyleContext* direct = AsDirect();
+  return direct && direct->GetPseudo() == aPseudoTag ? direct : nullptr;
+}
+
+void
+CachedInheritingStyles::AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const
+{
+  if (IsIndirect()) {
+    for (auto& style : *AsIndirect()) {
+      if (!aSizes.mState.HaveSeenPtr(style)) {
+        style->AddSizeOfIncludingThis(aSizes, aCVsSize);
+      }
+    }
+
+    return;
+  }
+
+  ServoStyleContext* direct = AsDirect();
+  if (direct && !aSizes.mState.HaveSeenPtr(direct)) {
+    direct->AddSizeOfIncludingThis(aSizes, aCVsSize);
+  }
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/CachedInheritingStyles.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_CachedInheritingStyles_h
+#define mozilla_CachedInheritingStyles_h
+
+#include "nsAtom.h"
+#include "nsTArray.h"
+
+class nsWindowSizes;
+
+namespace mozilla {
+
+class ServoStyleContext;
+
+// Cache of anonymous box and lazy pseudo styles that inherit from a given style.
+//
+// To minimize memory footprint, the cache is word-sized with a tagged pointer
+// If there is only one entry, it's stored inline. If there are more, they're
+// stored in an out-of-line buffer. See bug 1429126 comment 0 and comment 1 for
+// the measurements and rationale that influenced the design.
+class CachedInheritingStyles
+{
+public:
+  void Insert(ServoStyleContext* aStyle);
+  ServoStyleContext* Lookup(nsAtom* aPseudoTag) const;
+
+  CachedInheritingStyles() : mBits(0) {}
+  ~CachedInheritingStyles()
+  {
+    if (IsIndirect()) {
+      delete AsIndirect();
+    } else if (!IsEmpty()) {
+      RefPtr<ServoStyleContext> ref = dont_AddRef(AsDirect());
+    }
+  }
+
+  void AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const;
+
+private:
+  // See bug 1429126 comment 1 for the choice of four here.
+  typedef AutoTArray<RefPtr<ServoStyleContext>, 4> IndirectCache;
+
+  bool IsEmpty() const { return !mBits; }
+  bool IsIndirect() const { return (mBits & 1); }
+
+  ServoStyleContext* AsDirect() const
+  {
+    MOZ_ASSERT(!IsIndirect());
+    return reinterpret_cast<ServoStyleContext*>(mBits);
+  }
+
+  IndirectCache* AsIndirect() const
+  {
+    MOZ_ASSERT(IsIndirect());
+    return reinterpret_cast<IndirectCache*>(mBits & ~1);
+  }
+
+  uintptr_t mBits;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_CachedInheritingStyles_h
--- a/layout/style/ServoStyleContext.h
+++ b/layout/style/ServoStyleContext.h
@@ -7,17 +7,17 @@
 #ifndef mozilla_ServoStyleContext_h
 #define mozilla_ServoStyleContext_h
 
 #include "nsIMemoryReporter.h"
 #include "nsStyleContext.h"
 #include "nsWindowSizes.h"
 #include <algorithm>
 
-#include "mozilla/CachedAnonBoxStyles.h"
+#include "mozilla/CachedInheritingStyles.h"
 
 namespace mozilla {
 
 namespace dom {
 class Element;
 } // namespace dom
 
 MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoComputedValuesMallocEnclosingSizeOf)
@@ -45,23 +45,23 @@ public:
   {
     return IsPseudoElement() &&
            !nsCSSPseudoElements::IsEagerlyCascadedInServo(GetPseudoType());
   }
 
   ServoStyleContext* GetCachedInheritingAnonBoxStyle(nsAtom* aAnonBox) const
   {
     MOZ_ASSERT(nsCSSAnonBoxes::IsInheritingAnonBox(aAnonBox));
-    return mInheritingAnonBoxStyles.Lookup(aAnonBox);
+    return mCachedInheritingStyles.Lookup(aAnonBox);
   }
 
   void SetCachedInheritedAnonBoxStyle(nsAtom* aAnonBox, ServoStyleContext* aStyle)
   {
     MOZ_ASSERT(!GetCachedInheritingAnonBoxStyle(aAnonBox));
-    mInheritingAnonBoxStyles.Insert(aStyle);
+    mCachedInheritingStyles.Insert(aStyle);
   }
 
   ServoStyleContext* GetCachedLazyPseudoStyle(CSSPseudoElementType aPseudo) const;
 
   void SetCachedLazyPseudoStyle(ServoStyleContext* aStyle)
   {
     MOZ_ASSERT(aStyle->GetPseudo() && !aStyle->IsAnonBox());
     MOZ_ASSERT(!GetCachedLazyPseudoStyle(aStyle->GetPseudoType()));
@@ -98,31 +98,30 @@ public:
   void AddSizeOfIncludingThis(nsWindowSizes& aSizes, size_t* aCVsSize) const
   {
     // Note: |this| sits within a servo_arc::Arc, i.e. it is preceded by a
     // refcount. So we need to measure it with a function that can handle an
     // interior pointer. We use ServoComputedValuesMallocEnclosingSizeOf to
     // clearly identify in DMD's output the memory measured here.
     *aCVsSize += ServoComputedValuesMallocEnclosingSizeOf(this);
     mSource.AddSizeOfExcludingThis(aSizes);
-    mInheritingAnonBoxStyles.AddSizeOfIncludingThis(aSizes, aCVsSize);
+    mCachedInheritingStyles.AddSizeOfIncludingThis(aSizes, aCVsSize);
 
     if (mNextLazyPseudoStyle &&
         !aSizes.mState.HaveSeenPtr(mNextLazyPseudoStyle)) {
       mNextLazyPseudoStyle->AddSizeOfIncludingThis(aSizes, aCVsSize);
     }
   }
 
 private:
   nsPresContext* mPresContext;
   ServoComputedData mSource;
 
-  // A cache of inheriting anon boxes inheriting from this style _if the style
-  // isn't an inheriting anon-box_.
-  CachedAnonBoxStyles mInheritingAnonBoxStyles;
+  // A cache of anonymous box and lazy pseudo styles inheriting from this style.
+  CachedInheritingStyles mCachedInheritingStyles;
 
   // A linked-list cache of lazy pseudo styles inheriting from this style _if
   // the style isn't a lazy pseudo style itself_.
   //
   // Otherwise it represents the next entry in the cache of the parent style
   // context.
   //
   // Note that we store these separately from inheriting anonymous boxes so that
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -76,17 +76,17 @@ EXPORTS += [
     'nsStyleStructInlines.h',
     'nsStyleTransformMatrix.h',
     'nsStyleUtil.h',
 ]
 
 EXPORTS.mozilla += [
     'AnimationCollection.h',
     'BindingStyleRule.h',
-    'CachedAnonBoxStyles.h',
+    'CachedInheritingStyles.h',
     'CSSEnabledState.h',
     'CSSStyleSheet.h',
     'CSSVariableDeclarations.h',
     'CSSVariableResolver.h',
     'CSSVariableValues.h',
     'DeclarationBlock.h',
     'DeclarationBlockInlines.h',
     'DocumentStyleRootIterator.h',
@@ -175,17 +175,17 @@ EXPORTS.mozilla.css += [
     'StreamLoader.h',
     'StyleRule.h',
     'URLMatchingFunction.h',
 ]
 
 UNIFIED_SOURCES += [
     'AnimationCollection.cpp',
     'BindingStyleRule.cpp',
-    'CachedAnonBoxStyles.cpp',
+    'CachedInheritingStyles.cpp',
     'CounterStyleManager.cpp',
     'CSS.cpp',
     'CSSFontFeatureValuesRule.cpp',
     'CSSImportRule.cpp',
     'CSSKeyframeRule.cpp',
     'CSSKeyframesRule.cpp',
     'CSSLexer.cpp',
     'CSSMediaRule.cpp',