NodeRareData doesn't need to have a vtable pointer
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2013 05:23:04 +0000 (05:23 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Jan 2013 05:23:04 +0000 (05:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=106965

Reviewed by Benjamin Poulain.

Made the destructor and reportMemoryUsage of NodeRareDataBase and NodeRareData
respectively and their subclasses non-virtual.

* dom/ElementRareData.cpp:
(SameSizeAsElementRareData): Added.
(WebCore): Added a compile assertion for the size of ElementRareData.
* dom/ElementRareData.h:
(ElementRareData):
* dom/Node.cpp:
(WebCore::Node::clearRareData): Explicitely delete NodeRareData or ElementRareData.
(WebCore::Node::reportMemoryUsage): Explicitely add NodeRareData or ElementRareData.
* dom/Node.h:
(NodeRareDataBase): Deleted the virtual destructor.
* dom/NodeRareData.cpp:
(SameSizeAsNodeRareData): Removed one pointer.
* dom/NodeRareData.h:
(NodeRareData): Removed the virtual destructor.
(NodeRareData::reportMemoryUsage): Made non-virtual.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@139833 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/ElementRareData.cpp
Source/WebCore/dom/ElementRareData.h
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/dom/NodeRareData.cpp
Source/WebCore/dom/NodeRareData.h

index a481cf0ccde4c09000eee85934055af5ecc06e81..ee71ea98f10b5b3ef5d4d4696d74300f96b1c1e8 100644 (file)
@@ -1,3 +1,29 @@
+2013-01-15  Ryosuke Niwa  <rniwa@webkit.org>
+
+        NodeRareData doesn't need to have a vtable pointer
+        https://bugs.webkit.org/show_bug.cgi?id=106965
+
+        Reviewed by Benjamin Poulain.
+
+        Made the destructor and reportMemoryUsage of NodeRareDataBase and NodeRareData
+        respectively and their subclasses non-virtual.
+
+        * dom/ElementRareData.cpp:
+        (SameSizeAsElementRareData): Added.
+        (WebCore): Added a compile assertion for the size of ElementRareData.
+        * dom/ElementRareData.h:
+        (ElementRareData):
+        * dom/Node.cpp:
+        (WebCore::Node::clearRareData): Explicitely delete NodeRareData or ElementRareData.
+        (WebCore::Node::reportMemoryUsage): Explicitely add NodeRareData or ElementRareData.
+        * dom/Node.h:
+        (NodeRareDataBase): Deleted the virtual destructor.
+        * dom/NodeRareData.cpp:
+        (SameSizeAsNodeRareData): Removed one pointer.
+        * dom/NodeRareData.h:
+        (NodeRareData): Removed the virtual destructor.
+        (NodeRareData::reportMemoryUsage): Made non-virtual.
+
 2013-01-15  Ian Vollick  <vollick@chromium.org>
 
         [chromium] Create GraphicsLayerChromiums using a factory
index 1c92940114f5dcaf8b7964ad4ac34b2f63ae5eff..382f219809521356c3e2ddfe72730234c8f64987 100644 (file)
 
 namespace WebCore {
 
+struct SameSizeAsElementRareData : NodeRareData {
+    short indices[2];
+    unsigned bitfields;
+    LayoutSize sizeForResizing;
+    IntSize scrollOffset;
+    void* pointers[7];
+};
+
+COMPILE_ASSERT(sizeof(ElementRareData) == sizeof(SameSizeAsElementRareData), ElementRareDataShouldStaySmall);
+
 void ElementRareData::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
 {
     MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
index f2bfb702fe6661caebbfce3915f30ef523d9376a..8c73beff95b4495d7f7c97d2b8fa2b06692f5156 100644 (file)
@@ -36,7 +36,7 @@ namespace WebCore {
 class ElementRareData : public NodeRareData {
 public:
     ElementRareData();
-    virtual ~ElementRareData();
+    ~ElementRareData();
 
     void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
     PseudoElement* pseudoElement(PseudoId) const;
@@ -94,7 +94,8 @@ public:
     unsigned childIndex() const { return m_childIndex; }
     void setChildIndex(unsigned index) { m_childIndex = index; }
 
-    virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
+    // Manually called by Node::reportMemoryUsage.
+    void reportMemoryUsage(MemoryObjectInfo*) const;
 
     ElementShadow* shadow() const { return m_shadow.get(); }
     void setShadow(PassOwnPtr<ElementShadow> shadow) { m_shadow = shadow; }
@@ -160,6 +161,7 @@ private:
 #endif
 
     LayoutSize m_minimumSizeForResizing;
+    IntSize m_savedLayerScrollOffset;
     RefPtr<RenderStyle> m_computedStyle;
 
     OwnPtr<DatasetDOMStringMap> m_dataset;
@@ -170,9 +172,6 @@ private:
     RefPtr<PseudoElement> m_generatedBefore;
     RefPtr<PseudoElement> m_generatedAfter;
 
-    IntSize m_savedLayerScrollOffset;
-
-private:
     void releasePseudoElement(PseudoElement*);
 };
 
index ce2a5a46bfb1fc1ebafba2c1e5a0f716bad31956..ffab27b2be5e89d33b3c865c16884aafed50ed13 100644 (file)
@@ -471,7 +471,10 @@ void Node::clearRareData()
     ASSERT(!transientMutationObserverRegistry() || transientMutationObserverRegistry()->isEmpty());
 
     RenderObject* renderer = m_data.m_rareData->renderer();
-    delete m_data.m_rareData;
+    if (isElementNode())
+        delete static_cast<ElementRareData*>(m_data.m_rareData);
+    else
+        delete m_data.m_rareData;
     m_data.m_renderer = renderer;
     clearFlag(HasRareDataFlag);
 }
@@ -2581,8 +2584,12 @@ void Node::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
     info.addMember(m_next);
     info.addMember(m_previous);
     info.addMember(this->renderer());
-    if (hasRareData())
-        info.addMember(rareData());
+    if (hasRareData()) {
+        if (isElementNode())
+            info.addMember(static_cast<ElementRareData*>(rareData()));
+        else
+            info.addMember(rareData());
+    }
 }
 
 void Node::textRects(Vector<IntRect>& rects) const
index 9de59958104c4c3e0c699afcf9a2cec546c54fee..1845ff8839a5891fe143b2b28245f04fbe169fde 100644 (file)
@@ -115,9 +115,9 @@ public:
     RenderObject* renderer() const { return m_renderer; }
     void setRenderer(RenderObject* renderer) { m_renderer = renderer; }
 
-    virtual ~NodeRareDataBase() { }
 protected:
     NodeRareDataBase() { }
+
 private:
     RenderObject* m_renderer;
 };
index 2bdfc94c894ebb7f33a9c74025b5d347418e0cc5..618a48b9e6482a1ab9b4ce42402296dfc0ad2613 100644 (file)
@@ -39,7 +39,7 @@
 namespace WebCore {
 
 struct SameSizeAsNodeRareData {
-    void* m_pointer[4];
+    void* m_pointer[3];
 #if ENABLE(MICRODATA)
     void* m_microData;
 #endif
index 51735d2307e2f20385cc0a1290a6d82161342790..2720af6725fb609802e6884dffeb287244a70612 100644 (file)
@@ -280,9 +280,6 @@ public:
     NodeRareData()
     { }
 
-    virtual ~NodeRareData()
-    { }
-
     void clearNodeLists() { m_nodeLists.clear(); }
     NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); }
     NodeListsNodeData* ensureNodeLists()
@@ -309,7 +306,8 @@ public:
     }
 #endif
 
-    virtual void reportMemoryUsage(MemoryObjectInfo*) const;
+    // This member function is intentionially not virtual to avoid adding a vtable pointer.
+    void reportMemoryUsage(MemoryObjectInfo*) const;
 
 private:
     OwnPtr<NodeListsNodeData> m_nodeLists;