From 50e884b3930bdd84bb9d7f3b55cafe68019546e0 Mon Sep 17 00:00:00 2001 From: Mounir Lamouri Date: Tue, 19 Jul 2011 10:46:01 -0700 Subject: [PATCH] Bug 670962 - Make nsGenericDOMDataNode and nsTextFragment participate to the DOM Memory Reporter. r=jst --- content/base/src/nsGenericDOMDataNode.cpp | 12 +++++++++++- content/base/src/nsGenericDOMDataNode.h | 3 +++ content/base/src/nsTextFragment.h | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index bf3f9624dc72..c1332111aec2 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -67,7 +67,7 @@ #include "pldhash.h" #include "prprf.h" -namespace css = mozilla::css; +using namespace mozilla; nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed aNodeInfo) : nsIContent(aNodeInfo) @@ -1065,3 +1065,13 @@ nsGenericDOMDataNode::GetClassAttributeName() const { return nsnull; } + +PRInt64 +nsGenericDOMDataNode::SizeOf() const +{ + PRInt64 size = dom::MemoryReporter::GetBasicSize(this); + size += mText.SizeOf() - sizeof(mText); + return size; +} + diff --git a/content/base/src/nsGenericDOMDataNode.h b/content/base/src/nsGenericDOMDataNode.h index d341123431df..07c341c7aa52 100644 --- a/content/base/src/nsGenericDOMDataNode.h +++ b/content/base/src/nsGenericDOMDataNode.h @@ -51,6 +51,7 @@ #include "nsGenericElement.h" #include "nsCycleCollectionParticipant.h" #include "nsContentUtils.h" +#include "nsDOMMemoryReporter.h" #ifdef MOZ_SMIL #include "nsISMILAttr.h" @@ -84,6 +85,8 @@ class nsGenericDOMDataNode : public nsIContent public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_DOM_MEMORY_REPORTER_SIZEOF + nsGenericDOMDataNode(already_AddRefed aNodeInfo); virtual ~nsGenericDOMDataNode(); diff --git a/content/base/src/nsTextFragment.h b/content/base/src/nsTextFragment.h index c9510fc82feb..f5124f91275c 100644 --- a/content/base/src/nsTextFragment.h +++ b/content/base/src/nsTextFragment.h @@ -47,6 +47,8 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsTraceRefcnt.h" +#include "nsDOMMemoryReporter.h" + class nsString; class nsCString; @@ -224,6 +226,21 @@ public: PRUint32 mLength : 29; }; + /** + * Returns the size taken in memory by this text fragment. + * @return the size taken in memory by this text fragment. + */ + PRInt64 SizeOf() const + { + PRInt64 size = sizeof(*this); + + if (mState.mInHeap) { + size += GetLength() * Is2b() ? sizeof(*m2b) : sizeof(*m1b); + } + + return size; + } + private: void ReleaseText();