Bug 1328420 Part 8: Uplift SizeOfIncludingThis into StyleSheet, with override in CSSStyleSheet. r=heycam
authorBrad Werth <bwerth@mozilla.com>
Mon, 23 Jan 2017 16:42:31 -0800
changeset 377575 b3bfcc29a57981b6819b3ee9b2d4d7971b7383e5
parent 377574 99b47f5198fc42356516f7f400c818b7f7be8305
child 377576 6d8d5b5d1aa699f149851cd9c3034c1ccc6b24b1
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1328420
milestone54.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 1328420 Part 8: Uplift SizeOfIncludingThis into StyleSheet, with override in CSSStyleSheet. r=heycam MozReview-Commit-ID: 5f1WldhnP2
layout/style/CSSStyleSheet.cpp
layout/style/CSSStyleSheet.h
layout/style/ServoStyleSheet.cpp
layout/style/ServoStyleSheet.h
layout/style/StyleSheet.cpp
layout/style/StyleSheet.h
layout/style/StyleSheetInlines.h
--- a/layout/style/CSSStyleSheet.cpp
+++ b/layout/style/CSSStyleSheet.cpp
@@ -203,36 +203,32 @@ CSSStyleSheet::RebuildChildList(css::Rul
   builder->SetParentLinks(*builder->sheetSlot);
   builder->sheetSlot = &(*builder->sheetSlot)->mNext;
   return true;
 }
 
 size_t
 CSSStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
 {
-  size_t n = 0;
+  size_t n = StyleSheet::SizeOfIncludingThis(aMallocSizeOf);
   const CSSStyleSheet* s = this;
   while (s) {
-    n += aMallocSizeOf(s);
-
     // Each inner can be shared by multiple sheets.  So we only count the inner
     // if this sheet is the last one in the list of those sharing it.  As a
     // result, the last such sheet takes all the blame for the memory
     // consumption of the inner, which isn't ideal but it's better than
     // double-counting the inner.  We use last instead of first since the first
     // sheet may be held in the nsXULPrototypeCache and not used in a window at
     // all.
     if (s->mInner->mSheets.LastElement() == s) {
       n += s->mInner->SizeOfIncludingThis(aMallocSizeOf);
     }
 
     // Measurement of the following members may be added later if DMD finds it
     // is worthwhile:
-    // - s->mTitle
-    // - s->mMedia
     // - s->mRuleCollection
     // - s->mRuleProcessors
     //
     // The following members are not measured:
     // - s->mOwnerRule, because it's non-owning
 
     s = s->mNext ? s->mNext->AsGecko() : nullptr;
   }
--- a/layout/style/CSSStyleSheet.h
+++ b/layout/style/CSSStyleSheet.h
@@ -164,17 +164,17 @@ public:
   nsresult ReparseSheet(const nsAString& aInput);
 
   void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
 
   // Function used as a callback to rebuild our inner's child sheet
   // list after we clone a unique inner for ourselves.
   static bool RebuildChildList(css::Rule* aRule, void* aBuilder);
 
-  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
 
   dom::Element* GetScopeElement() const { return mScopeElement; }
   void SetScopeElement(dom::Element* aScopeElement)
   {
     mScopeElement = aScopeElement;
   }
 
   // WebIDL CSSStyleSheet API
--- a/layout/style/ServoStyleSheet.cpp
+++ b/layout/style/ServoStyleSheet.cpp
@@ -104,22 +104,16 @@ void
 ServoStyleSheet::DropRuleList()
 {
   if (mRuleList) {
     mRuleList->DropReference();
     mRuleList = nullptr;
   }
 }
 
-size_t
-ServoStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
-{
-  MOZ_CRASH("stylo: not implemented");
-}
-
 css::Rule*
 ServoStyleSheet::GetDOMOwnerRule() const
 {
   NS_ERROR("stylo: Don't know how to get DOM owner rule for ServoStyleSheet");
   return nullptr;
 }
 
 CSSRuleList*
--- a/layout/style/ServoStyleSheet.h
+++ b/layout/style/ServoStyleSheet.h
@@ -48,18 +48,16 @@ public:
 
   /**
    * Called instead of ParseSheet to initialize the Servo stylesheet object
    * for a failed load. Either ParseSheet or LoadFailed must be called before
    * adding a ServoStyleSheet to a ServoStyleSet.
    */
   void LoadFailed();
 
-  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
-
   RawServoStyleSheet* RawSheet() const { return mSheet; }
   void SetSheetForImport(RawServoStyleSheet* aSheet) {
     MOZ_ASSERT(!mSheet);
     mSheet = aSheet;
   }
 
   // WebIDL CSSStyleSheet API
   // Can't be inline because we can't include ImportRule here.  And can't be
--- a/layout/style/StyleSheet.cpp
+++ b/layout/style/StyleSheet.cpp
@@ -427,16 +427,34 @@ StyleSheet::AppendStyleSheet(StyleSheet*
 
   // This is not reference counted. Our parent tells us when
   // it's going away.
   aSheet->mParent = this;
   aSheet->mDocument = mDocument;
   DidDirty();
 }
 
+size_t
+StyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
+{
+  size_t n = 0;
+  const StyleSheet* s = this;
+  while (s) {
+    n += aMallocSizeOf(s);
+
+    // Measurement of the following members may be added later if DMD finds it
+    // is worthwhile:
+    // - s->mTitle
+    // - s->mMedia
+
+    s = s->mNext;
+  }
+  return n;
+}
+
 #ifdef DEBUG
 void
 StyleSheet::List(FILE* out, int32_t aIndent) const
 {
   int32_t index;
 
   // Indent
   nsAutoCString str;
--- a/layout/style/StyleSheet.h
+++ b/layout/style/StyleSheet.h
@@ -146,17 +146,17 @@ public:
 
   // Get this style sheet's CORS mode
   inline CORSMode GetCORSMode() const;
   // Get this style sheet's Referrer Policy
   inline net::ReferrerPolicy GetReferrerPolicy() const;
   // Get this style sheet's integrity metadata
   inline void GetIntegrity(dom::SRIMetadata& aResult) const;
 
-  inline size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
+  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
 #ifdef DEBUG
   virtual void List(FILE* aOut = stdout, int32_t aIndex = 0) const;
 #endif
 
   // WebIDL StyleSheet API
   // The XPCOM GetType is fine for WebIDL.
   // The XPCOM GetHref is fine for WebIDL
   // GetOwnerNode is defined above.
--- a/layout/style/StyleSheetInlines.h
+++ b/layout/style/StyleSheetInlines.h
@@ -129,21 +129,15 @@ StyleSheet::GetReferrerPolicy() const
 }
 
 void
 StyleSheet::GetIntegrity(dom::SRIMetadata& aResult) const
 {
   aResult = SheetInfo().mIntegrity;
 }
 
-size_t
-StyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
-{
-  MOZ_STYLO_FORWARD(SizeOfIncludingThis, (aMallocSizeOf))
-}
-
 void StyleSheet::WillDirty() { MOZ_STYLO_FORWARD(WillDirty, ()) }
 void StyleSheet::DidDirty() { MOZ_STYLO_FORWARD(DidDirty, ()) }
 
 
 }
 
 #endif // mozilla_StyleSheetInlines_h