Bug 670962 - Make nsGenericDOMDataNode and nsTextFragment participate to the DOM Memory Reporter. r=jst
authorMounir Lamouri <mounir.lamouri@gmail.com>
Tue, 19 Jul 2011 10:04:09 -0700
changeset 73107 2f2e969cc11d80b5b6f9680daa3e25254839186a
parent 73106 b04f9b7ab97cdcfeec67575d76f71ed046245d9c
child 73108 1d35d254c9d7dabeec7c9725ddd9b7c1dab47947
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)
reviewersjst
bugs670962
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 670962 - Make nsGenericDOMDataNode and nsTextFragment participate to the DOM Memory Reporter. r=jst
content/base/src/nsGenericDOMDataNode.cpp
content/base/src/nsGenericDOMDataNode.h
content/base/src/nsTextFragment.h
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -62,17 +62,17 @@
 #include "nsBindingManager.h"
 #include "nsCCUncollectableMarker.h"
 #include "mozAutoDocUpdate.h"
 #include "nsPLDOMEvent.h"
 
 #include "pldhash.h"
 #include "prprf.h"
 
-namespace css = mozilla::css;
+using namespace mozilla;
 
 nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsIContent(aNodeInfo)
 {
   NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE ||
                     mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE ||
                     mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE ||
                     mNodeInfo->NodeType() ==
@@ -1060,8 +1060,18 @@ nsGenericDOMDataNode::GetAttributeChange
   return nsChangeHint(0);
 }
 
 nsIAtom*
 nsGenericDOMDataNode::GetClassAttributeName() const
 {
   return nsnull;
 }
+
+PRInt64
+nsGenericDOMDataNode::SizeOf() const
+{
+  PRInt64 size = dom::MemoryReporter::GetBasicSize<nsGenericDOMDataNode,
+                                                   nsIContent>(this);
+  size += mText.SizeOf() - sizeof(mText);
+  return size;
+}
+
--- a/content/base/src/nsGenericDOMDataNode.h
+++ b/content/base/src/nsGenericDOMDataNode.h
@@ -46,16 +46,17 @@
 #include "nsIContent.h"
 #include "nsIDOMCharacterData.h"
 #include "nsTextFragment.h"
 #include "nsDOMError.h"
 #include "nsEventListenerManager.h"
 #include "nsGenericElement.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsContentUtils.h"
+#include "nsDOMMemoryReporter.h"
 
 #ifdef MOZ_SMIL
 #include "nsISMILAttr.h"
 #endif // MOZ_SMIL
 
 // This bit is set to indicate that if the text node changes to
 // non-whitespace, we may need to create a frame for it. This bit must
 // not be set on nodes that already have a frame.
@@ -79,16 +80,18 @@ class nsIDOMText;
 class nsINodeInfo;
 class nsURI;
 
 class nsGenericDOMDataNode : public nsIContent
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
 
+  NS_DECL_DOM_MEMORY_REPORTER_SIZEOF
+
   nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~nsGenericDOMDataNode();
 
   // Implementation for nsIDOMNode
   nsresult GetNodeName(nsAString& aNodeName)
   {
     aNodeName = NodeName();
     return NS_OK;
--- a/content/base/src/nsTextFragment.h
+++ b/content/base/src/nsTextFragment.h
@@ -42,16 +42,18 @@
  */
 
 #ifndef nsTextFragment_h___
 #define nsTextFragment_h___
 
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsTraceRefcnt.h"
+#include "nsDOMMemoryReporter.h"
+
 class nsString;
 class nsCString;
 
 // XXX should this normalize the code to keep a \u0000 at the end?
 
 // XXX nsTextFragmentPool?
 
 // XXX these need I18N spankage
@@ -219,16 +221,27 @@ public:
     // which causes crashes because we assume this structure is no more than
     // 32 bits!
     PRUint32 mInHeap : 1;
     PRUint32 mIs2b : 1;
     PRUint32 mIsBidi : 1;
     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);
+    size += GetLength() * Is2b() ? sizeof(*m2b) : sizeof(*m1b);
+    return size;
+  }
+
 private:
   void ReleaseText();
 
   union {
     PRUnichar *m2b;
     const char *m1b; // This is const since it can point to shared data
   };