From cc533eaee5b800a534b93484598779debcdf5591 Mon Sep 17 00:00:00 2001 From: Gaming4JC Date: Sat, 4 Jan 2020 19:48:30 -0500 Subject: Bug 1377993 - Make node slots less memory hungry in common cases. Tag UXP Issue #1344 --- dom/base/FragmentOrElement.h | 128 +++++++++++++++++++++++++++---------------- 1 file changed, 81 insertions(+), 47 deletions(-) (limited to 'dom/base/FragmentOrElement.h') diff --git a/dom/base/FragmentOrElement.h b/dom/base/FragmentOrElement.h index a3a59ee43..4edd88908 100644 --- a/dom/base/FragmentOrElement.h +++ b/dom/base/FragmentOrElement.h @@ -15,6 +15,7 @@ #include "mozilla/Attributes.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/UniquePtr.h" #include "nsAttrAndChildArray.h" // member #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_* #include "nsIContent.h" // base class @@ -239,8 +240,6 @@ protected: nsresult CopyInnerTo(FragmentOrElement* aDest); public: - // Because of a bug in MS C++ compiler nsDOMSlots must be declared public, - // otherwise nsXULElement::nsXULSlots doesn't compile. /** * There are a set of DOM- and scripting-specific instance variables * that may only be instantiated when a content object is accessed @@ -249,29 +248,13 @@ public: * in a side structure that's only allocated when the content is * accessed through the DOM. */ - class nsDOMSlots : public nsINode::nsSlots + + class nsExtendedDOMSlots { public: - nsDOMSlots(); - virtual ~nsDOMSlots(); - - void Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL); - void Unlink(bool aIsXUL); - - size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; - - /** - * The .style attribute (an interface that forwards to the actual - * style rules) - * @see nsGenericHTMLElement::GetStyle - */ - nsCOMPtr mStyle; + nsExtendedDOMSlots(); - /** - * The .dataset attribute. - * @see nsGenericHTMLElement::GetDataset - */ - nsDOMStringMap* mDataset; // [Weak] + ~nsExtendedDOMSlots(); /** * SMIL Overridde style rules (for SMIL animation of CSS properties) @@ -285,35 +268,17 @@ public: RefPtr mSMILOverrideStyleDeclaration; /** - * An object implementing nsIDOMMozNamedAttrMap for this content (attributes) - * @see FragmentOrElement::GetAttributes - */ - RefPtr mAttributeMap; - - union { - /** - * The nearest enclosing content node with a binding that created us. - * @see FragmentOrElement::GetBindingParent - */ - nsIContent* mBindingParent; // [Weak] - - /** - * The controllers of the XUL Element. - */ - nsIControllers* mControllers; // [OWNER] - }; + * The nearest enclosing content node with a binding that created us. + * @see FragmentOrElement::GetBindingParent + */ + nsIContent* mBindingParent; // [Weak] /** - * An object implementing the .children property for this element. - */ - RefPtr mChildrenList; + * The controllers of the XUL Element. + */ + nsCOMPtr mControllers; /** - * An object implementing the .classList property for this element. - */ - RefPtr mClassList; - - /* * An object implementing the .labels property for this element. */ RefPtr mLabelsList; @@ -354,6 +319,55 @@ public: */ nsDataHashtable, int32_t> mRegisteredIntersectionObservers; + + /** + * For XUL to hold either frameloader or opener. + */ + nsCOMPtr mFrameLoaderOrOpener; + + }; + + class nsDOMSlots : public nsINode::nsSlots + { + public: + nsDOMSlots(); + virtual ~nsDOMSlots(); + + void Traverse(nsCycleCollectionTraversalCallback &cb); + void Unlink(); + + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; + + /** + * The .style attribute (an interface that forwards to the actual + * style rules) + * @see nsGenericHTMLElement::GetStyle + */ + nsCOMPtr mStyle; + + /** + * The .dataset attribute. + * @see nsGenericHTMLElement::GetDataset + */ + nsDOMStringMap* mDataset; // [Weak] + + /** + * An object implementing nsIDOMMozNamedAttrMap for this content (attributes) + * @see FragmentOrElement::GetAttributes + */ + RefPtr mAttributeMap; + + /** + * An object implementing the .children property for this element. + */ + RefPtr mChildrenList; + + /** + * An object implementing the .classList property for this element. + */ + RefPtr mClassList; + + mozilla::UniquePtr mExtendedSlots; }; protected: @@ -373,6 +387,26 @@ protected: return static_cast(GetExistingSlots()); } + nsExtendedDOMSlots* ExtendedDOMSlots() + { + nsDOMSlots* slots = DOMSlots(); + if (!slots->mExtendedSlots) { + slots->mExtendedSlots = MakeUnique(); + } + + return slots->mExtendedSlots.get(); + } + + nsExtendedDOMSlots* GetExistingExtendedDOMSlots() const + { + nsDOMSlots* slots = GetExistingDOMSlots(); + if (slots) { + return slots->mExtendedSlots.get(); + } + + return nullptr; + } + /** * Calls SetIsElementInStyleScopeFlagOnSubtree for each shadow tree attached * to this node, which is assumed to be an Element. -- cgit v1.2.3