From b511862894597eae8f90cf4fe253e2a300c413e6 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Tue, 19 Jul 2011 09:40:18 -0700 Subject: [PATCH] Bug 668013 - Add nsHTMLStyleSheet::SizeOf(). r=bz --- content/base/public/nsIDocument.h | 4 ++-- content/base/src/nsDocument.cpp | 8 +++++++ content/base/src/nsDocument.h | 1 + layout/style/nsHTMLStyleSheet.cpp | 38 +++++++++++++++++++++++++++++++ layout/style/nsHTMLStyleSheet.h | 1 + 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index 9fcec4368247..631647b7a0b6 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -69,6 +69,7 @@ #include "nsIAnimationFrameListener.h" #include "nsEventStates.h" #include "nsIStructuredCloneContainer.h" +#include "nsDOMMemoryReporter.h" class nsIContent; class nsPresContext; @@ -149,6 +150,7 @@ public: 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() @@ -1531,8 +1533,6 @@ public: #undef DEPRECATED_OPERATION void WarnOnceAbout(DeprecatedOperations aOperation); - PRInt64 SizeOf() const; - private: PRUint32 mWarnedAbout; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 252d32ee14de..9bca208b4960 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -8383,3 +8383,11 @@ nsIDocument::SizeOf() const return size; } +PRInt64 +nsDocument::SizeOf() const +{ + PRInt64 size = MemoryReporter::GetBasicSize(this); + size += mAttrStyleSheet ? mAttrStyleSheet->SizeOf() : 0; + return size; +} + diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 27762d877bd4..a79106d62772 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -499,6 +499,7 @@ public: typedef mozilla::dom::Element Element; NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_DOM_MEMORY_REPORTER_SIZEOF using nsINode::GetScriptTypeID; diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index f81fb80b6f15..e5c95faa211e 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -528,6 +528,43 @@ nsHTMLStyleSheet::List(FILE* out, PRInt32 aIndent) const } #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(aEntry); + PRInt64 size = *static_cast(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(&mMappedAttrTable), + GetHashEntryAttributesSize, &size); + } + + return size; +} + // XXX For convenience and backwards compatibility nsresult NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL, @@ -567,3 +604,4 @@ NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult) *aInstancePtrResult = it; // NS_ADDREF above, or set to null by NS_RELEASE return rv; } + diff --git a/layout/style/nsHTMLStyleSheet.h b/layout/style/nsHTMLStyleSheet.h index 661534a0c7e2..7ca31a38f5d3 100644 --- a/layout/style/nsHTMLStyleSheet.h +++ b/layout/style/nsHTMLStyleSheet.h @@ -101,6 +101,7 @@ public: UniqueMappedAttributes(nsMappedAttributes* aMapped); void DropMappedAttributes(nsMappedAttributes* aMapped); + PRInt64 SizeOf() const; private: // These are not supported and are not implemented!