Title: [143014] trunk/Source/WebCore
Revision
143014
Author
[email protected]
Date
2013-02-15 10:28:12 -0800 (Fri, 15 Feb 2013)

Log Message

ElementData: Move leafy things out of the base class.
<http://webkit.org/b/109888>

Reviewed by Antti Koivisto.

- Moved functions for mutating/adding/removing attributes into UniqueElementData.
  Attempts to modify shared element data will now fail at compile-time.

- Removed mutableAttributeVector() and have call sites access the vector directly.

- Move immutableAttributeArray() to ShareableElementData.

- Move some function bodies from Element.h to Element.cpp since all clients are in there.

* dom/Element.cpp:
(WebCore::Element::addAttributeInternal):
(WebCore::ShareableElementData::ShareableElementData):
(WebCore::UniqueElementData::makeShareableCopy):
(WebCore::UniqueElementData::addAttribute):
(WebCore::UniqueElementData::removeAttribute):
(WebCore::ElementData::reportMemoryUsage):
(WebCore::UniqueElementData::getAttributeItem):
(WebCore::UniqueElementData::attributeItem):
* dom/Element.h:
(ElementData):
(WebCore::ShareableElementData::immutableAttributeArray):
(ShareableElementData):
(UniqueElementData):
(WebCore::ElementData::length):
(WebCore::ElementData::attributeItem):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (143013 => 143014)


--- trunk/Source/WebCore/ChangeLog	2013-02-15 18:27:49 UTC (rev 143013)
+++ trunk/Source/WebCore/ChangeLog	2013-02-15 18:28:12 UTC (rev 143014)
@@ -1,3 +1,36 @@
+2013-02-15  Andreas Kling  <[email protected]>
+
+        ElementData: Move leafy things out of the base class.
+        <http://webkit.org/b/109888>
+
+        Reviewed by Antti Koivisto.
+
+        - Moved functions for mutating/adding/removing attributes into UniqueElementData.
+          Attempts to modify shared element data will now fail at compile-time.
+
+        - Removed mutableAttributeVector() and have call sites access the vector directly.
+
+        - Move immutableAttributeArray() to ShareableElementData.
+
+        - Move some function bodies from Element.h to Element.cpp since all clients are in there.
+
+        * dom/Element.cpp:
+        (WebCore::Element::addAttributeInternal):
+        (WebCore::ShareableElementData::ShareableElementData):
+        (WebCore::UniqueElementData::makeShareableCopy):
+        (WebCore::UniqueElementData::addAttribute):
+        (WebCore::UniqueElementData::removeAttribute):
+        (WebCore::ElementData::reportMemoryUsage):
+        (WebCore::UniqueElementData::getAttributeItem):
+        (WebCore::UniqueElementData::attributeItem):
+        * dom/Element.h:
+        (ElementData):
+        (WebCore::ShareableElementData::immutableAttributeArray):
+        (ShareableElementData):
+        (UniqueElementData):
+        (WebCore::ElementData::length):
+        (WebCore::ElementData::attributeItem):
+
 2013-02-15  Hans Muller  <[email protected]>
 
         [CSS Exclusions] Enable shape-inside support for circles

Modified: trunk/Source/WebCore/dom/Element.cpp (143013 => 143014)


--- trunk/Source/WebCore/dom/Element.cpp	2013-02-15 18:27:49 UTC (rev 143013)
+++ trunk/Source/WebCore/dom/Element.cpp	2013-02-15 18:28:12 UTC (rev 143014)
@@ -1788,7 +1788,7 @@
 {
     if (!inSynchronizationOfLazyAttribute)
         willModifyAttribute(name, nullAtom, value);
-    ensureUniqueElementData()->addAttribute(Attribute(name, value));
+    ensureUniqueElementData()->addAttribute(name, value);
     if (!inSynchronizationOfLazyAttribute)
         didAddAttribute(name, value);
 }
@@ -2901,7 +2901,7 @@
     }
 
     for (unsigned i = 0; i < m_arraySize; ++i)
-        new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(*other.attributeItem(i));
+        new (&reinterpret_cast<Attribute*>(&m_attributeArray)[i]) Attribute(other.m_attributeVector.at(i));
 }
 
 ElementData::ElementData(const ElementData& other, bool isUnique)
@@ -2951,21 +2951,19 @@
 
 PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const
 {
-    void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(mutableAttributeVector().size()));
+    void* slot = WTF::fastMalloc(sizeForShareableElementDataWithAttributeCount(m_attributeVector.size()));
     return adoptRef(new (slot) ShareableElementData(*this));
 }
 
-void ElementData::addAttribute(const Attribute& attribute)
+void UniqueElementData::addAttribute(const QualifiedName& attributeName, const AtomicString& value)
 {
-    ASSERT(isUnique());
-    mutableAttributeVector().append(attribute);
+    m_attributeVector.append(Attribute(attributeName, value));
 }
 
-void ElementData::removeAttribute(size_t index)
+void UniqueElementData::removeAttribute(size_t index)
 {
-    ASSERT(isUnique());
     ASSERT_WITH_SECURITY_IMPLICATION(index < length());
-    mutableAttributeVector().remove(index);
+    m_attributeVector.remove(index);
 }
 
 bool ElementData::isEquivalent(const ElementData* other) const
@@ -2995,8 +2993,9 @@
     info.addMember(m_classNames, "classNames");
     info.addMember(m_idForStyleResolution, "idForStyleResolution");
     if (m_isUnique) {
-        info.addMember(presentationAttributeStyle(), "presentationAttributeStyle()");
-        info.addMember(mutableAttributeVector(), "mutableAttributeVector");
+        const UniqueElementData* uniqueThis = static_cast<const UniqueElementData*>(this);
+        info.addMember(uniqueThis->m_presentationAttributeStyle, "presentationAttributeStyle");
+        info.addMember(uniqueThis->m_attributeVector, "attributeVector");
     }
     for (unsigned i = 0, len = length(); i < len; i++)
         info.addMember(*attributeItem(i), "*attributeItem");
@@ -3021,4 +3020,19 @@
     return notFound;
 }
 
+Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name)
+{
+    for (unsigned i = 0; i < length(); ++i) {
+        if (m_attributeVector.at(i).name().matches(name))
+            return &m_attributeVector.at(i);
+    }
+    return 0;
+}
+
+Attribute* UniqueElementData::attributeItem(unsigned index)
+{
+    ASSERT_WITH_SECURITY_IMPLICATION(index < length());
+    return &m_attributeVector.at(index);
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/Element.h (143013 => 143014)


--- trunk/Source/WebCore/dom/Element.h	2013-02-15 18:27:49 UTC (rev 143013)
+++ trunk/Source/WebCore/dom/Element.h	2013-02-15 18:28:12 UTC (rev 143014)
@@ -75,15 +75,9 @@
 
     const Attribute* attributeItem(unsigned index) const;
     const Attribute* getAttributeItem(const QualifiedName&) const;
-    Attribute* attributeItem(unsigned index);
-    Attribute* getAttributeItem(const QualifiedName&);
     size_t getAttributeItemIndex(const QualifiedName&) const;
     size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
 
-    // These functions do no error checking.
-    void addAttribute(const Attribute&);
-    void removeAttribute(size_t index);
-
     bool hasID() const { return !m_idForStyleResolution.isNull(); }
     bool hasClass() const { return !m_classNames.isNull(); }
 
@@ -92,7 +86,6 @@
     void reportMemoryUsage(MemoryObjectInfo*) const;
 
     bool isUnique() const { return m_isUnique; }
-    const Attribute* immutableAttributeArray() const;
 
 protected:
     ElementData();
@@ -120,20 +113,18 @@
     friend class SVGElement;
 #endif
 
-    Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase);
     const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
     size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
 
     PassRefPtr<UniqueElementData> makeUniqueCopy() const;
-
-    Vector<Attribute, 4>& mutableAttributeVector();
-    const Vector<Attribute, 4>& mutableAttributeVector() const;
 };
 
 class ShareableElementData : public ElementData {
 public:
     static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
 
+    const Attribute* immutableAttributeArray() const { return reinterpret_cast<const Attribute*>(&m_attributeArray); }
+
     explicit ShareableElementData(const Vector<Attribute>&);
     explicit ShareableElementData(const UniqueElementData&);
     ~ShareableElementData();
@@ -146,6 +137,13 @@
     static PassRefPtr<UniqueElementData> create();
     PassRefPtr<ShareableElementData> makeShareableCopy() const;
 
+    // These functions do no error/duplicate checking.
+    void addAttribute(const QualifiedName&, const AtomicString&);
+    void removeAttribute(size_t index);
+
+    Attribute* attributeItem(unsigned index);
+    Attribute* getAttributeItem(const QualifiedName&);
+
     UniqueElementData();
     explicit UniqueElementData(const ShareableElementData&);
     explicit UniqueElementData(const UniqueElementData&);
@@ -968,28 +966,11 @@
 {
     return node && node->isElementNode() && toElement(node)->shadow();
 }
-inline Vector<Attribute, 4>& ElementData::mutableAttributeVector()
-{
-    ASSERT(m_isUnique);
-    return static_cast<UniqueElementData*>(this)->m_attributeVector;
-}
 
-inline const Vector<Attribute, 4>& ElementData::mutableAttributeVector() const
-{
-    ASSERT(m_isUnique);
-    return static_cast<const UniqueElementData*>(this)->m_attributeVector;
-}
-
-inline const Attribute* ElementData::immutableAttributeArray() const
-{
-    ASSERT(!m_isUnique);
-    return reinterpret_cast<const Attribute*>(&static_cast<const ShareableElementData*>(this)->m_attributeArray);
-}
-
 inline size_t ElementData::length() const
 {
     if (isUnique())
-        return mutableAttributeVector().size();
+        return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
     return m_arraySize;
 }
 
@@ -1000,14 +981,6 @@
     return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();
 }
 
-inline Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase)
-{
-    size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
-    if (index != notFound)
-        return attributeItem(index);
-    return 0;
-}
-
 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
 {
     size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
@@ -1056,29 +1029,14 @@
     return 0;
 }
 
-inline Attribute* ElementData::getAttributeItem(const QualifiedName& name)
-{
-    for (unsigned i = 0; i < length(); ++i) {
-        if (attributeItem(i)->name().matches(name))
-            return attributeItem(i);
-    }
-    return 0;
-}
-
 inline const Attribute* ElementData::attributeItem(unsigned index) const
 {
     ASSERT_WITH_SECURITY_IMPLICATION(index < length());
     if (m_isUnique)
-        return &mutableAttributeVector().at(index);
-    return &immutableAttributeArray()[index];
+        return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index);
+    return &static_cast<const ShareableElementData*>(this)->immutableAttributeArray()[index];
 }
 
-inline Attribute* ElementData::attributeItem(unsigned index)
-{
-    ASSERT_WITH_SECURITY_IMPLICATION(index < length());
-    return &mutableAttributeVector().at(index);
-}
-
 } // namespace
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to