Title: [174329] trunk/Source/WebCore
Revision
174329
Author
[email protected]
Date
2014-10-05 15:14:47 -0700 (Sun, 05 Oct 2014)

Log Message

Use is<>() / downcast<>() for ElementData subclasses
https://bugs.webkit.org/show_bug.cgi?id=137430

Reviewed by Benjamin Poulain.

Use is<>() / downcast<>() for ElementData subclasses.

No new tests, no behavior change.

* dom/Element.cpp:
(WebCore::Element::cloneAttributesFromElement):
(WebCore::Element::createUniqueElementData):
* dom/ElementData.cpp:
(WebCore::ElementData::destroy):
* dom/ElementData.h:
(WebCore::ElementData::length):
(WebCore::ElementData::attributeBase):
(WebCore::ElementData::presentationAttributeStyle):
(WebCore::ElementData::attributesIterator):
(WebCore::ElementData::findAttributeByName):
(isType):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (174328 => 174329)


--- trunk/Source/WebCore/ChangeLog	2014-10-05 11:28:30 UTC (rev 174328)
+++ trunk/Source/WebCore/ChangeLog	2014-10-05 22:14:47 UTC (rev 174329)
@@ -1,3 +1,27 @@
+2014-10-05  Christophe Dumez  <[email protected]>
+
+        Use is<>() / downcast<>() for ElementData subclasses
+        https://bugs.webkit.org/show_bug.cgi?id=137430
+
+        Reviewed by Benjamin Poulain.
+
+        Use is<>() / downcast<>() for ElementData subclasses.
+
+        No new tests, no behavior change.
+
+        * dom/Element.cpp:
+        (WebCore::Element::cloneAttributesFromElement):
+        (WebCore::Element::createUniqueElementData):
+        * dom/ElementData.cpp:
+        (WebCore::ElementData::destroy):
+        * dom/ElementData.h:
+        (WebCore::ElementData::length):
+        (WebCore::ElementData::attributeBase):
+        (WebCore::ElementData::presentationAttributeStyle):
+        (WebCore::ElementData::attributesIterator):
+        (WebCore::ElementData::findAttributeByName):
+        (isType):
+
 2014-10-05  Lorenzo Tilve  <[email protected]>
 
         [GTK] Fix build when DRAG_SUPPORT is disabled

Modified: trunk/Source/WebCore/dom/Element.cpp (174328 => 174329)


--- trunk/Source/WebCore/dom/Element.cpp	2014-10-05 11:28:30 UTC (rev 174328)
+++ trunk/Source/WebCore/dom/Element.cpp	2014-10-05 22:14:47 UTC (rev 174329)
@@ -2938,10 +2938,10 @@
 
     // If 'other' has a mutable ElementData, convert it to an immutable one so we can share it between both elements.
     // We can only do this if there is no CSSOM wrapper for other's inline style, and there are no presentation attributes.
-    if (other.m_elementData->isUnique()
+    if (is<UniqueElementData>(*other.m_elementData)
         && !other.m_elementData->presentationAttributeStyle()
         && (!other.m_elementData->inlineStyle() || !other.m_elementData->inlineStyle()->hasCSSOMWrapper()))
-        const_cast<Element&>(other).m_elementData = toUniqueElementData(other.m_elementData)->makeShareableCopy();
+        const_cast<Element&>(other).m_elementData = downcast<UniqueElementData>(*other.m_elementData).makeShareableCopy();
 
     if (!other.m_elementData->isUnique())
         m_elementData = other.m_elementData;
@@ -2963,7 +2963,7 @@
     if (!m_elementData)
         m_elementData = UniqueElementData::create();
     else
-        m_elementData = toShareableElementData(m_elementData)->makeUniqueCopy();
+        m_elementData = downcast<ShareableElementData>(*m_elementData).makeUniqueCopy();
 }
 
 bool Element::hasPendingResources() const

Modified: trunk/Source/WebCore/dom/ElementData.cpp (174328 => 174329)


--- trunk/Source/WebCore/dom/ElementData.cpp	2014-10-05 11:28:30 UTC (rev 174328)
+++ trunk/Source/WebCore/dom/ElementData.cpp	2014-10-05 22:14:47 UTC (rev 174329)
@@ -35,10 +35,10 @@
 
 void ElementData::destroy()
 {
-    if (isUnique())
-        delete toUniqueElementData(this);
+    if (is<UniqueElementData>(*this))
+        delete downcast<UniqueElementData>(this);
     else
-        delete toShareableElementData(this);
+        delete downcast<ShareableElementData>(this);
 }
 
 ElementData::ElementData()

Modified: trunk/Source/WebCore/dom/ElementData.h (174328 => 174329)


--- trunk/Source/WebCore/dom/ElementData.h	2014-10-05 11:28:30 UTC (rev 174328)
+++ trunk/Source/WebCore/dom/ElementData.h	2014-10-05 22:14:47 UTC (rev 174329)
@@ -29,6 +29,7 @@
 #include "Attribute.h"
 #include "SpaceSplitString.h"
 #include <wtf/RefCounted.h>
+#include <wtf/TypeCasts.h>
 
 namespace WebCore {
 
@@ -181,10 +182,6 @@
     PassRef<UniqueElementData> makeUniqueCopy() const;
 };
 
-#define ELEMENT_DATA_TYPE_CASTS(ToValueTypeName, pointerPredicate, referencePredicate) \
-    template<typename T> inline ToValueTypeName* to##ToValueTypeName(const RefPtr<T>& elementData) { return to##ToValueTypeName(elementData.get()); } \
-    TYPE_CASTS_BASE(ToValueTypeName, ElementData, elementData, pointerPredicate, referencePredicate)
-
 #if COMPILER(MSVC)
 #pragma warning(push)
 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
@@ -203,8 +200,6 @@
     Attribute m_attributeArray[0];
 };
 
-ELEMENT_DATA_TYPE_CASTS(ShareableElementData, !elementData->isUnique(), !elementData.isUnique())
-
 #if COMPILER(MSVC)
 #pragma warning(pop)
 #endif
@@ -232,8 +227,6 @@
     AttributeVector m_attributeVector;
 };
 
-ELEMENT_DATA_TYPE_CASTS(UniqueElementData, elementData->isUnique(), elementData.isUnique())
-
 inline void ElementData::deref()
 {
     if (!derefBase())
@@ -243,32 +236,32 @@
 
 inline unsigned ElementData::length() const
 {
-    if (isUnique())
-        return toUniqueElementData(this)->m_attributeVector.size();
+    if (is<UniqueElementData>(*this))
+        return downcast<UniqueElementData>(*this).m_attributeVector.size();
     return arraySize();
 }
 
 inline const Attribute* ElementData::attributeBase() const
 {
-    if (isUnique())
-        return toUniqueElementData(this)->m_attributeVector.data();
-    return toShareableElementData(this)->m_attributeArray;
+    if (is<UniqueElementData>(*this))
+        return downcast<UniqueElementData>(*this).m_attributeVector.data();
+    return downcast<ShareableElementData>(*this).m_attributeArray;
 }
 
 inline const StyleProperties* ElementData::presentationAttributeStyle() const
 {
-    if (!isUnique())
-        return 0;
-    return toUniqueElementData(this)->m_presentationAttributeStyle.get();
+    if (!is<UniqueElementData>(*this))
+        return nullptr;
+    return downcast<UniqueElementData>(*this).m_presentationAttributeStyle.get();
 }
 
 inline AttributeIteratorAccessor ElementData::attributesIterator() const
 {
-    if (isUnique()) {
-        const Vector<Attribute, 4>& attributeVector = toUniqueElementData(this)->m_attributeVector;
+    if (is<UniqueElementData>(*this)) {
+        const Vector<Attribute, 4>& attributeVector = downcast<UniqueElementData>(*this).m_attributeVector;
         return AttributeIteratorAccessor(attributeVector.data(), attributeVector.size());
     }
-    return AttributeIteratorAccessor(toShareableElementData(this)->m_attributeArray, arraySize());
+    return AttributeIteratorAccessor(downcast<ShareableElementData>(*this).m_attributeArray, arraySize());
 }
 
 ALWAYS_INLINE const Attribute* ElementData::findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const
@@ -276,7 +269,7 @@
     unsigned index = findAttributeIndexByName(name, shouldIgnoreAttributeCase);
     if (index != attributeNotFound)
         return &attributeAt(index);
-    return 0;
+    return nullptr;
 }
 
 ALWAYS_INLINE unsigned ElementData::findAttributeIndexByName(const QualifiedName& name) const
@@ -342,7 +335,15 @@
     return m_attributeVector.at(index);
 }
 
-}
+} // namespace WebCore
 
-#endif
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ShareableElementData)
+    static bool isType(const WebCore::ElementData& elementData) { return !elementData.isUnique(); }
+SPECIALIZE_TYPE_TRAITS_END()
 
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::UniqueElementData)
+    static bool isType(const WebCore::ElementData& elementData) { return elementData.isUnique(); }
+SPECIALIZE_TYPE_TRAITS_END()
+
+#endif // ElementData_h
+
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to