Stronger ElementData pointer typing.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 01:07:01 +0000 (01:07 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Feb 2013 01:07:01 +0000 (01:07 +0000)
<http://webkit.org/b/109752>

Reviewed by Antti Koivisto.

Use ShareableElementData/UniqueElementData pointers instead of generic ElementData pointers
where possible. Moved some methods from base class into leaf classes that don't make sense
for both classes.

* dom/DocumentSharedObjectPool.cpp:
(WebCore::ShareableElementDataCacheEntry::ShareableElementDataCacheEntry):
(ShareableElementDataCacheEntry):
(WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
* dom/DocumentSharedObjectPool.h:
(DocumentSharedObjectPool):
* dom/Element.cpp:
(WebCore::Element::parserSetAttributes):
(WebCore::Element::setAttributeNode):
(WebCore::Element::removeAttributeInternal):
(WebCore::Element::cloneAttributesFromElement):
(WebCore::Element::createUniqueElementData):
(WebCore::ShareableElementData::createWithAttributes):
(WebCore::UniqueElementData::create):
(WebCore::ElementData::makeUniqueCopy):
(WebCore::UniqueElementData::makeShareableCopy):
* dom/Element.h:
(ElementData):
(ShareableElementData):
(UniqueElementData):
(Element):
(WebCore::Element::ensureUniqueElementData):
* dom/StyledElement.cpp:
(WebCore::StyledElement::rebuildPresentationAttributeStyle):

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

Source/WebCore/ChangeLog
Source/WebCore/dom/DocumentSharedObjectPool.cpp
Source/WebCore/dom/DocumentSharedObjectPool.h
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/dom/StyledElement.cpp

index 4e3aa15e8648af41bc83a4228217dc4860cf5480..ae24167eac9a37e6e75574c84550dc21fe9148c0 100644 (file)
@@ -1,3 +1,39 @@
+2013-02-13  Andreas Kling  <akling@apple.com>
+
+        Stronger ElementData pointer typing.
+        <http://webkit.org/b/109752>
+
+        Reviewed by Antti Koivisto.
+
+        Use ShareableElementData/UniqueElementData pointers instead of generic ElementData pointers
+        where possible. Moved some methods from base class into leaf classes that don't make sense
+        for both classes.
+
+        * dom/DocumentSharedObjectPool.cpp:
+        (WebCore::ShareableElementDataCacheEntry::ShareableElementDataCacheEntry):
+        (ShareableElementDataCacheEntry):
+        (WebCore::DocumentSharedObjectPool::cachedShareableElementDataWithAttributes):
+        * dom/DocumentSharedObjectPool.h:
+        (DocumentSharedObjectPool):
+        * dom/Element.cpp:
+        (WebCore::Element::parserSetAttributes):
+        (WebCore::Element::setAttributeNode):
+        (WebCore::Element::removeAttributeInternal):
+        (WebCore::Element::cloneAttributesFromElement):
+        (WebCore::Element::createUniqueElementData):
+        (WebCore::ShareableElementData::createWithAttributes):
+        (WebCore::UniqueElementData::create):
+        (WebCore::ElementData::makeUniqueCopy):
+        (WebCore::UniqueElementData::makeShareableCopy):
+        * dom/Element.h:
+        (ElementData):
+        (ShareableElementData):
+        (UniqueElementData):
+        (Element):
+        (WebCore::Element::ensureUniqueElementData):
+        * dom/StyledElement.cpp:
+        (WebCore::StyledElement::rebuildPresentationAttributeStyle):
+
 2013-02-13  Antti Koivisto  <antti@apple.com>
 
         Reschedule shared CFRunLoopTimer instead of reconstructing it
index 0af630c2c142414a4dbf999a15f2ae7f28074cb1..0301000e90e8c82c0370a962ee17b376a8e770d7 100644 (file)
@@ -57,16 +57,16 @@ private:
 
 class ShareableElementDataCacheEntry {
 public:
-    ShareableElementDataCacheEntry(const ShareableElementDataCacheKey& k, PassRefPtr<ElementData> v)
+    ShareableElementDataCacheEntry(const ShareableElementDataCacheKey& k, PassRefPtr<ShareableElementData> v)
         : key(k)
         , value(v)
     { }
 
     ShareableElementDataCacheKey key;
-    RefPtr<ElementData> value;
+    RefPtr<ShareableElementData> value;
 };
 
-PassRefPtr<ElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes)
+PassRefPtr<ShareableElementData> DocumentSharedObjectPool::cachedShareableElementDataWithAttributes(const Vector<Attribute>& attributes)
 {
     ASSERT(!attributes.isEmpty());
 
@@ -77,11 +77,11 @@ PassRefPtr<ElementData> DocumentSharedObjectPool::cachedShareableElementDataWith
     if (cacheIterator->value && cacheIterator->value->key != cacheKey)
         cacheHash = 0;
 
-    RefPtr<ElementData> elementData;
+    RefPtr<ShareableElementData> elementData;
     if (cacheHash && cacheIterator->value)
         elementData = cacheIterator->value->value;
     else
-        elementData = ElementData::createShareableWithAttributes(attributes);
+        elementData = ShareableElementData::createWithAttributes(attributes);
 
     if (!cacheHash || cacheIterator->value)
         return elementData.release();
index 0ef056cfa8e46d5fedfafded4f1cfeefa016322e..a3b24d739f79985a75017db0571f891c78ba4ef2 100644 (file)
@@ -34,7 +34,7 @@
 namespace WebCore {
 
 class Attribute;
-class ElementData;
+class ShareableElementData;
 class ShareableElementDataCacheEntry;
 
 class DocumentSharedObjectPool {
@@ -42,7 +42,7 @@ public:
     static PassOwnPtr<DocumentSharedObjectPool> create() { return adoptPtr(new DocumentSharedObjectPool); }
     ~DocumentSharedObjectPool();
 
-    PassRefPtr<ElementData> cachedShareableElementDataWithAttributes(const Vector<Attribute>&);
+    PassRefPtr<ShareableElementData> cachedShareableElementDataWithAttributes(const Vector<Attribute>&);
 
 private:
     DocumentSharedObjectPool();
index c75271c79537785c78a58c4a2df85115374ac809..c058290b5adc4bd1e0ccbf8f616927f80bbfa592 100644 (file)
@@ -1022,7 +1022,7 @@ void Element::parserSetAttributes(const Vector<Attribute>& attributeVector, Frag
     if (document() && document()->sharedObjectPool())
         m_elementData = document()->sharedObjectPool()->cachedShareableElementDataWithAttributes(filteredAttributes);
     else
-        m_elementData = ElementData::createShareableWithAttributes(filteredAttributes);
+        m_elementData = ShareableElementData::createWithAttributes(filteredAttributes);
 
     // Iterate over the set of attributes we already have on the stack in case
     // attributeChanged mutates m_elementData.
@@ -1687,7 +1687,7 @@ PassRefPtr<Attr> Element::setAttributeNode(Attr* attrNode, ExceptionCode& ec)
     }
 
     updateInvalidAttributes();
-    ElementData* elementData = ensureUniqueElementData();
+    UniqueElementData* elementData = ensureUniqueElementData();
 
     size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName());
     if (index != notFound) {
@@ -1765,7 +1765,7 @@ void Element::removeAttributeInternal(size_t index, SynchronizationOfLazyAttribu
 {
     ASSERT_WITH_SECURITY_IMPLICATION(index < attributeCount());
 
-    ElementData* elementData = ensureUniqueElementData();
+    UniqueElementData* elementData = ensureUniqueElementData();
 
     QualifiedName name = elementData->attributeItem(index)->name();
     AtomicString valueBeingRemoved = elementData->attributeItem(index)->value();
@@ -2767,7 +2767,7 @@ void Element::cloneAttributesFromElement(const Element& other)
     if (other.m_elementData->isUnique()
         && !other.m_elementData->presentationAttributeStyle()
         && (!other.m_elementData->inlineStyle() || !other.m_elementData->inlineStyle()->hasCSSOMWrapper()))
-        const_cast<Element&>(other).m_elementData = other.m_elementData->makeShareableCopy();
+        const_cast<Element&>(other).m_elementData = static_cast<const UniqueElementData*>(other.m_elementData.get())->makeShareableCopy();
 
     if (!other.m_elementData->isUnique())
         m_elementData = other.m_elementData;
@@ -2789,9 +2789,11 @@ void Element::cloneDataFromElement(const Element& other)
 void Element::createUniqueElementData()
 {
     if (!m_elementData)
-        m_elementData = ElementData::createUnique();
-    else
-        m_elementData = m_elementData->makeUniqueCopy();
+        m_elementData = UniqueElementData::create();
+    else {
+        ASSERT(!m_elementData->isUnique());
+        m_elementData = static_cast<ShareableElementData*>(m_elementData.get())->makeUniqueCopy();
+    }
 }
 
 void Element::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
@@ -2864,13 +2866,13 @@ static size_t sizeForShareableElementDataWithAttributeCount(unsigned count)
     return sizeof(ShareableElementData) - sizeof(void*) + sizeof(Attribute) * count;
 }
 
-PassRefPtr<ElementData> ElementData::createShareableWithAttributes(const Vector<Attribute>& attributes)
+PassRefPtr<ShareableElementData> ShareableElementData::createWithAttributes(const Vector<Attribute>& attributes)
 {
     void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(attributes.size()));
     return adoptRef(new (slot) ShareableElementData(attributes));
 }
 
-PassRefPtr<ElementData> ElementData::createUnique()
+PassRefPtr<UniqueElementData> UniqueElementData::create()
 {
     return adoptRef(new UniqueElementData);
 }
@@ -2940,24 +2942,17 @@ UniqueElementData::UniqueElementData(const ShareableElementData& other)
         m_attributeVector.uncheckedAppend(other.immutableAttributeArray()[i]);
 }
 
-PassRefPtr<ElementData> ElementData::makeUniqueCopy() const
+PassRefPtr<UniqueElementData> ElementData::makeUniqueCopy() const
 {
     if (isUnique())
         return adoptRef(new UniqueElementData(static_cast<const UniqueElementData&>(*this)));
     return adoptRef(new UniqueElementData(static_cast<const ShareableElementData&>(*this)));
 }
 
-PassRefPtr<ElementData> ElementData::makeShareableCopy() const
+PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const
 {
-    ASSERT(isUnique());
     void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(mutableAttributeVector().size()));
-    return adoptRef(new (slot) ShareableElementData(static_cast<const UniqueElementData&>(*this)));
-}
-
-void ElementData::setPresentationAttributeStyle(PassRefPtr<StylePropertySet> style) const
-{
-    ASSERT(m_isUnique);
-    static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle = style;
+    return adoptRef(new (slot) ShareableElementData(*this));
 }
 
 void ElementData::addAttribute(const Attribute& attribute)
index c8067a5284f43c811ce2cc7fc810926f9c4e16c5..2fa430ada69dbb273e3ff8cb8aec57a87de476c9 100644 (file)
@@ -55,9 +55,6 @@ class StylePropertySet;
 class ElementData : public RefCounted<ElementData> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static PassRefPtr<ElementData> createUnique();
-    static PassRefPtr<ElementData> createShareableWithAttributes(const Vector<Attribute>&);
-
     // Override RefCounted's deref() to ensure operator delete is called on
     // the appropriate subclass type.
     void deref();
@@ -72,7 +69,6 @@ public:
     const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); }
 
     const StylePropertySet* presentationAttributeStyle() const;
-    void setPresentationAttributeStyle(PassRefPtr<StylePropertySet>) const;
 
     size_t length() const;
     bool isEmpty() const { return !length(); }
@@ -128,8 +124,7 @@ private:
     const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
     size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
 
-    PassRefPtr<ElementData> makeUniqueCopy() const;
-    PassRefPtr<ElementData> makeShareableCopy() const;
+    PassRefPtr<UniqueElementData> makeUniqueCopy() const;
 
     Vector<Attribute, 4>& mutableAttributeVector();
     const Vector<Attribute, 4>& mutableAttributeVector() const;
@@ -137,8 +132,10 @@ private:
 
 class ShareableElementData : public ElementData {
 public:
-    ShareableElementData(const Vector<Attribute>&);
-    ShareableElementData(const UniqueElementData&);
+    static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
+
+    explicit ShareableElementData(const Vector<Attribute>&);
+    explicit ShareableElementData(const UniqueElementData&);
     ~ShareableElementData();
 
     void* m_attributeArray;
@@ -146,9 +143,12 @@ public:
 
 class UniqueElementData : public ElementData {
 public:
+    static PassRefPtr<UniqueElementData> create();
+    PassRefPtr<ShareableElementData> makeShareableCopy() const;
+
     UniqueElementData();
-    UniqueElementData(const ShareableElementData&);
-    UniqueElementData(const UniqueElementData&);
+    explicit UniqueElementData(const ShareableElementData&);
+    explicit UniqueElementData(const UniqueElementData&);
 
     mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;
     Vector<Attribute, 4> m_attributeVector;
@@ -372,9 +372,9 @@ public:
     void parserSetAttributes(const Vector<Attribute>&, FragmentScriptingPermission);
 
     const ElementData* elementData() const { return m_elementData.get(); }
-    ElementData* ensureUniqueElementData();
     const ElementData* elementDataWithSynchronizedAttributes() const;
     const ElementData* ensureElementDataWithSynchronizedAttributes() const;
+    UniqueElementData* ensureUniqueElementData();
 
     // Clones attributes only.
     void cloneAttributesFromElement(const Element&);
@@ -934,11 +934,11 @@ inline bool Element::hasClass() const
     return elementData() && elementData()->hasClass();
 }
 
-inline ElementData* Element::ensureUniqueElementData()
+inline UniqueElementData* Element::ensureUniqueElementData()
 {
     if (!elementData() || !elementData()->isUnique())
         createUniqueElementData();
-    return m_elementData.get();
+    return static_cast<UniqueElementData*>(m_elementData.get());
 }
 
 // Put here to make them inline.
index 9edb39e121466b02736110de04feb3f896066c47..b6bbac63d9493ebae4efb081e9407fc685caf86e 100644 (file)
@@ -341,10 +341,10 @@ void StyledElement::rebuildPresentationAttributeStyle()
     }
 
     // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData.
-    ElementData* elementData = ensureUniqueElementData();
+    UniqueElementData* elementData = ensureUniqueElementData();
 
     elementData->m_presentationAttributeStyleIsDirty = false;
-    elementData->setPresentationAttributeStyle(style->isEmpty() ? 0 : style);
+    elementData->m_presentationAttributeStyle = style->isEmpty() ? 0 : style;
 
     if (!cacheHash || cacheIterator->value)
         return;