Bug 668013 - Add nsHTMLStyleSheet::SizeOf(). r=bz
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 19 Jul 2011 09:40:18 -0700
changeset 73104 2faa486ba8acc31040c7e43bf1dfd8ab7473a147
parent 73103 2996df7215caf063f664c784ffc5f9ed8b5af8b7
child 73105 281900cbb045bed4b5f7e57bfbd8ee73f209036b
push id20819
push usermak77@bonardo.net
push dateThu, 21 Jul 2011 12:32:52 +0000
treeherdermozilla-central@036c28e4e0f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs668013
milestone8.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 668013 - Add nsHTMLStyleSheet::SizeOf(). r=bz
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
layout/style/nsHTMLStyleSheet.cpp
layout/style/nsHTMLStyleSheet.h
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -64,16 +64,17 @@
 #ifdef MOZ_SMIL
 #include "nsSMILAnimationController.h"
 #endif // MOZ_SMIL
 #include "nsIScriptGlobalObject.h"
 #include "nsIDocumentEncoder.h"
 #include "nsIAnimationFrameListener.h"
 #include "nsEventStates.h"
 #include "nsIStructuredCloneContainer.h"
+#include "nsDOMMemoryReporter.h"
 
 class nsIContent;
 class nsPresContext;
 class nsIPresShell;
 class nsIDocShell;
 class nsStyleSet;
 class nsIStyleSheet;
 class nsIStyleRule;
@@ -144,16 +145,17 @@ class Element;
 // Gecko.
 class nsIDocument : public nsINode
 {
 public:
   typedef mozilla::dom::Element Element;
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
+  NS_DECL_DOM_MEMORY_REPORTER_SIZEOF
 
 #ifdef MOZILLA_INTERNAL_API
   nsIDocument()
     : nsINode(nsnull),
       mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
       mNodeInfoManager(nsnull),
       mCompatMode(eCompatibility_FullStandards),
       mIsInitialDocumentInWindow(PR_FALSE),
@@ -1526,18 +1528,16 @@ public:
 #define DEPRECATED_OPERATION(_op) e##_op,
   enum DeprecatedOperations {
 #include "nsDeprecatedOperationList.h"
     eDeprecatedOperationCount
   };
 #undef DEPRECATED_OPERATION
   void WarnOnceAbout(DeprecatedOperations aOperation);
 
-  PRInt64 SizeOf() const;
-
 private:
   PRUint32 mWarnedAbout;
 
 protected:
   ~nsIDocument()
   {
     // XXX The cleanup of mNodeInfoManager (calling DropDocumentReference and
     //     releasing it) happens in the nsDocument destructor. We'd prefer to
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -8378,8 +8378,16 @@ nsIDocument::SizeOf() const
   for (nsIContent* node = GetFirstChild(); node;
        node = node->GetNextNode(this)) {
     size += node->SizeOf();
   }
 
   return size;
 }
 
+PRInt64
+nsDocument::SizeOf() const
+{
+  PRInt64 size = MemoryReporter::GetBasicSize<nsDocument, nsIDocument>(this);
+  size += mAttrStyleSheet ? mAttrStyleSheet->SizeOf() : 0;
+  return size;
+}
+
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -494,16 +494,17 @@ class nsDocument : public nsIDocument,
                    public nsIApplicationCacheContainer,
                    public nsStubMutationObserver,
                    public nsIDOMDocumentTouch
 {
 public:
   typedef mozilla::dom::Element Element;
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_DOM_MEMORY_REPORTER_SIZEOF
 
   using nsINode::GetScriptTypeID;
 
   virtual void Reset(nsIChannel *aChannel, nsILoadGroup *aLoadGroup);
   virtual void ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup,
                           nsIPrincipal* aPrincipal);
 
   // StartDocumentLoad is pure virtual so that subclasses must override it.
--- a/layout/style/nsHTMLStyleSheet.cpp
+++ b/layout/style/nsHTMLStyleSheet.cpp
@@ -523,16 +523,53 @@ nsHTMLStyleSheet::List(FILE* out, PRInt3
   mURL->GetSpec(urlSpec);
   if (!urlSpec.IsEmpty()) {
     fputs(urlSpec.get(), out);
   }
   fputs("\n", out);
 }
 #endif
 
+static
+PLDHashOperator
+GetHashEntryAttributesSize(PLDHashTable* aTable, PLDHashEntryHdr* aEntry,
+                           PRUint32 number, void* aArg)
+{
+  NS_PRECONDITION(aEntry, "The entry should not be null!");
+  NS_PRECONDITION(aArg, "The passed argument should not be null!");
+
+  MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(aEntry);
+  PRInt64 size = *static_cast<PRInt64*>(aArg);
+
+  NS_ASSERTION(entry->mAttributes, "entry->mAttributes should not be null!");
+  size += sizeof(*entry->mAttributes);
+
+  return PL_DHASH_NEXT;
+}
+
+PRInt64
+nsHTMLStyleSheet::SizeOf() const
+{
+  PRInt64 size = sizeof(*this);
+
+  size += mLinkRule ? sizeof(*mLinkRule.get()) : 0;
+  size += mVisitedRule ? sizeof(*mVisitedRule.get()) : 0;
+  size += mActiveRule ? sizeof(*mActiveRule.get()) : 0;
+  size += mTableQuirkColorRule ? sizeof(*mTableQuirkColorRule.get()) : 0;
+  size += mTableTHRule ? sizeof(*mTableTHRule.get()) : 0;
+
+  if (mMappedAttrTable.ops) {
+    size += PL_DHASH_TABLE_SIZE(&mMappedAttrTable) * sizeof(MappedAttrTableEntry);
+    PL_DHashTableEnumerate(const_cast<PLDHashTable*>(&mMappedAttrTable),
+                           GetHashEntryAttributesSize, &size);
+  }
+
+  return size;
+}
+
 // XXX For convenience and backwards compatibility
 nsresult
 NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL, 
                      nsIDocument* aDocument)
 {
   nsresult rv;
   nsHTMLStyleSheet* sheet;
   if (NS_FAILED(rv = NS_NewHTMLStyleSheet(&sheet)))
@@ -562,8 +599,9 @@ NS_NewHTMLStyleSheet(nsHTMLStyleSheet** 
   NS_ADDREF(it);
   nsresult rv = it->Init();
   if (NS_FAILED(rv))
     NS_RELEASE(it);
 
   *aInstancePtrResult = it; // NS_ADDREF above, or set to null by NS_RELEASE
   return rv;
 }
+
--- a/layout/style/nsHTMLStyleSheet.h
+++ b/layout/style/nsHTMLStyleSheet.h
@@ -96,16 +96,17 @@ public:
   nsresult SetActiveLinkColor(nscolor aColor);
   nsresult SetVisitedLinkColor(nscolor aColor);
 
   // Mapped Attribute management methods
   already_AddRefed<nsMappedAttributes>
     UniqueMappedAttributes(nsMappedAttributes* aMapped);
   void DropMappedAttributes(nsMappedAttributes* aMapped);
 
+  PRInt64 SizeOf() const;
 
 private: 
   // These are not supported and are not implemented! 
   nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy); 
   nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy); 
 
   ~nsHTMLStyleSheet();