Title: [149061] trunk/Source/WebCore
Revision
149061
Author
[email protected]
Date
2013-04-24 13:03:12 -0700 (Wed, 24 Apr 2013)

Log Message

ElementData should use 'unsigned' attribute indices.
<http://webkit.org/b/115103>

Reviewed by Antti Koivisto.

Switch to using 'unsigned' for attribute indices. This gives consistent behavior
on 32/64-bit, and the underlying storage is already limited by Vector's 32-bit capacity.

Added an ElementData::attributeNotFound constant (-1) since we can't use WTF::notFound.

* dom/Element.cpp:
(WebCore::Element::detachAttribute):
(WebCore::Element::removeAttribute):
(WebCore::Element::setAttribute):
(WebCore::Element::setSynchronizedLazyAttribute):
(WebCore::Element::setAttributeInternal):
(WebCore::Element::setAttributeNode):
(WebCore::Element::removeAttributeNode):
(WebCore::Element::removeAttributeInternal):
(WebCore::UniqueElementData::removeAttribute):
(WebCore::ElementData::getAttributeItemIndexSlowCase):
* dom/Element.h:
(ElementData):
(UniqueElementData):
(Element):
(WebCore::Element::getAttributeItemIndex):
(WebCore::Element::attributeCount):
(WebCore::ElementData::length):
(WebCore::ElementData::getAttributeItem):
(WebCore::ElementData::getAttributeItemIndex):
* dom/NamedNodeMap.cpp:
(WebCore::NamedNodeMap::removeNamedItem):
(WebCore::NamedNodeMap::removeNamedItemNS):
(WebCore::NamedNodeMap::length):
* dom/NamedNodeMap.h:
(NamedNodeMap):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (149060 => 149061)


--- trunk/Source/WebCore/ChangeLog	2013-04-24 20:00:44 UTC (rev 149060)
+++ trunk/Source/WebCore/ChangeLog	2013-04-24 20:03:12 UTC (rev 149061)
@@ -1,5 +1,44 @@
 2013-04-24  Andreas Kling  <[email protected]>
 
+        ElementData should use 'unsigned' attribute indices.
+        <http://webkit.org/b/115103>
+
+        Reviewed by Antti Koivisto.
+
+        Switch to using 'unsigned' for attribute indices. This gives consistent behavior
+        on 32/64-bit, and the underlying storage is already limited by Vector's 32-bit capacity.
+
+        Added an ElementData::attributeNotFound constant (-1) since we can't use WTF::notFound.
+
+        * dom/Element.cpp:
+        (WebCore::Element::detachAttribute):
+        (WebCore::Element::removeAttribute):
+        (WebCore::Element::setAttribute):
+        (WebCore::Element::setSynchronizedLazyAttribute):
+        (WebCore::Element::setAttributeInternal):
+        (WebCore::Element::setAttributeNode):
+        (WebCore::Element::removeAttributeNode):
+        (WebCore::Element::removeAttributeInternal):
+        (WebCore::UniqueElementData::removeAttribute):
+        (WebCore::ElementData::getAttributeItemIndexSlowCase):
+        * dom/Element.h:
+        (ElementData):
+        (UniqueElementData):
+        (Element):
+        (WebCore::Element::getAttributeItemIndex):
+        (WebCore::Element::attributeCount):
+        (WebCore::ElementData::length):
+        (WebCore::ElementData::getAttributeItem):
+        (WebCore::ElementData::getAttributeItemIndex):
+        * dom/NamedNodeMap.cpp:
+        (WebCore::NamedNodeMap::removeNamedItem):
+        (WebCore::NamedNodeMap::removeNamedItemNS):
+        (WebCore::NamedNodeMap::length):
+        * dom/NamedNodeMap.h:
+        (NamedNodeMap):
+
+2013-04-24  Andreas Kling  <[email protected]>
+
         ElementData::attributeItem() should bounds-check the index.
         <http://webkit.org/b/115076>
 

Modified: trunk/Source/WebCore/dom/Element.cpp (149060 => 149061)


--- trunk/Source/WebCore/dom/Element.cpp	2013-04-24 20:00:44 UTC (rev 149060)
+++ trunk/Source/WebCore/dom/Element.cpp	2013-04-24 20:03:12 UTC (rev 149061)
@@ -280,7 +280,7 @@
     return document()->createElement(tagQName(), false);
 }
 
-PassRefPtr<Attr> Element::detachAttribute(size_t index)
+PassRefPtr<Attr> Element::detachAttribute(unsigned index)
 {
     ASSERT(elementData());
 
@@ -302,8 +302,8 @@
     if (!elementData())
         return;
 
-    size_t index = elementData()->getAttributeItemIndex(name);
-    if (index == notFound)
+    unsigned index = elementData()->getAttributeItemIndex(name);
+    if (index == ElementData::attributeNotFound)
         return;
 
     removeAttributeInternal(index, NotInSynchronizationOfLazyAttribute);
@@ -781,33 +781,33 @@
     synchronizeAttribute(localName);
     const AtomicString& caseAdjustedLocalName = shouldIgnoreAttributeCase(this) ? localName.lower() : localName;
 
-    size_t index = elementData() ? elementData()->getAttributeItemIndex(caseAdjustedLocalName, false) : notFound;
-    const QualifiedName& qName = index != notFound ? attributeItem(index)->name() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom);
+    unsigned index = elementData() ? elementData()->getAttributeItemIndex(caseAdjustedLocalName, false) : ElementData::attributeNotFound;
+    const QualifiedName& qName = index != ElementData::attributeNotFound ? attributeItem(index)->name() : QualifiedName(nullAtom, caseAdjustedLocalName, nullAtom);
     setAttributeInternal(index, qName, value, NotInSynchronizationOfLazyAttribute);
 }
 
 void Element::setAttribute(const QualifiedName& name, const AtomicString& value)
 {
     synchronizeAttribute(name);
-    size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : notFound;
+    unsigned index = elementData() ? elementData()->getAttributeItemIndex(name) : ElementData::attributeNotFound;
     setAttributeInternal(index, name, value, NotInSynchronizationOfLazyAttribute);
 }
 
 void Element::setSynchronizedLazyAttribute(const QualifiedName& name, const AtomicString& value)
 {
-    size_t index = elementData() ? elementData()->getAttributeItemIndex(name) : notFound;
+    unsigned index = elementData() ? elementData()->getAttributeItemIndex(name) : ElementData::attributeNotFound;
     setAttributeInternal(index, name, value, InSynchronizationOfLazyAttribute);
 }
 
-inline void Element::setAttributeInternal(size_t index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
+inline void Element::setAttributeInternal(unsigned index, const QualifiedName& name, const AtomicString& newValue, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
 {
     if (newValue.isNull()) {
-        if (index != notFound)
+        if (index != ElementData::attributeNotFound)
             removeAttributeInternal(index, inSynchronizationOfLazyAttribute);
         return;
     }
 
-    if (index == notFound) {
+    if (index == ElementData::attributeNotFound) {
         addAttributeInternal(name, newValue, inSynchronizationOfLazyAttribute);
         return;
     }
@@ -1765,8 +1765,8 @@
     synchronizeAllAttributes();
     UniqueElementData* elementData = ensureUniqueElementData();
 
-    size_t index = elementData->getAttributeItemIndex(attrNode->qualifiedName());
-    if (index != notFound) {
+    unsigned index = elementData->getAttributeItemIndex(attrNode->qualifiedName());
+    if (index != ElementData::attributeNotFound) {
         if (oldAttrNode)
             detachAttrNodeFromElementWithValue(oldAttrNode.get(), elementData->attributeItem(index)->value());
         else
@@ -1801,8 +1801,8 @@
 
     synchronizeAttribute(attr->qualifiedName());
 
-    size_t index = elementData()->getAttributeItemIndex(attr->qualifiedName());
-    if (index == notFound) {
+    unsigned index = elementData()->getAttributeItemIndex(attr->qualifiedName());
+    if (index == ElementData::attributeNotFound) {
         ec = NOT_FOUND_ERR;
         return 0;
     }
@@ -1836,7 +1836,7 @@
     setAttribute(parsedName, value);
 }
 
-void Element::removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
+void Element::removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute inSynchronizationOfLazyAttribute)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(index < attributeCount());
 
@@ -1874,8 +1874,8 @@
         return;
 
     AtomicString localName = shouldIgnoreAttributeCase(this) ? name.lower() : name;
-    size_t index = elementData()->getAttributeItemIndex(localName, false);
-    if (index == notFound) {
+    unsigned index = elementData()->getAttributeItemIndex(localName, false);
+    if (index == ElementData::attributeNotFound) {
         if (UNLIKELY(localName == styleAttr) && elementData()->m_styleAttributeIsDirty && isStyledElement())
             static_cast<StyledElement*>(this)->removeAllInlineStyleProperties();
         return;
@@ -3100,7 +3100,7 @@
     m_attributeVector.append(Attribute(attributeName, value));
 }
 
-void UniqueElementData::removeAttribute(size_t index)
+void UniqueElementData::removeAttribute(unsigned index)
 {
     ASSERT_WITH_SECURITY_IMPLICATION(index < length());
     m_attributeVector.remove(index);
@@ -3125,7 +3125,7 @@
     return true;
 }
 
-size_t ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const
+unsigned ElementData::getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const
 {
     // Continue to checking case-insensitively and/or full namespaced names if necessary:
     for (unsigned i = 0; i < length(); ++i) {
@@ -3141,7 +3141,7 @@
                 return i;
         }
     }
-    return notFound;
+    return attributeNotFound;
 }
 
 Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name)

Modified: trunk/Source/WebCore/dom/Element.h (149060 => 149061)


--- trunk/Source/WebCore/dom/Element.h	2013-04-24 20:00:44 UTC (rev 149060)
+++ trunk/Source/WebCore/dom/Element.h	2013-04-24 20:03:12 UTC (rev 149061)
@@ -58,6 +58,8 @@
     // the appropriate subclass type.
     void deref();
 
+    static const unsigned attributeNotFound = static_cast<unsigned>(-1);
+
     void clearClass() const { m_classNames.clear(); }
     void setClass(const AtomicString& className, bool shouldFoldCase) const { m_classNames.set(className, shouldFoldCase); }
     const SpaceSplitString& classNames() const { return m_classNames; }
@@ -69,13 +71,13 @@
 
     const StylePropertySet* presentationAttributeStyle() const;
 
-    size_t length() const;
+    unsigned length() const;
     bool isEmpty() const { return !length(); }
 
     const Attribute* attributeItem(unsigned index) const;
     const Attribute* getAttributeItem(const QualifiedName&) const;
-    size_t getAttributeItemIndex(const QualifiedName&) const;
-    size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
+    unsigned getAttributeItemIndex(const QualifiedName&) const;
+    unsigned getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
 
     bool hasID() const { return !m_idForStyleResolution.isNull(); }
     bool hasClass() const { return !m_classNames.isNull(); }
@@ -112,7 +114,7 @@
 
     const Attribute* attributeBase() const;
     const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
-    size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
+    unsigned getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
 
     PassRefPtr<UniqueElementData> makeUniqueCopy() const;
 };
@@ -144,7 +146,7 @@
 
     // These functions do no error/duplicate checking.
     void addAttribute(const QualifiedName&, const AtomicString&);
-    void removeAttribute(size_t index);
+    void removeAttribute(unsigned index);
 
     Attribute* attributeItem(unsigned index);
     Attribute* getAttributeItem(const QualifiedName&);
@@ -285,11 +287,11 @@
 
     // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
     // before calling them.
-    size_t attributeCount() const;
+    unsigned attributeCount() const;
     const Attribute* attributeItem(unsigned index) const;
     const Attribute* getAttributeItem(const QualifiedName&) const;
-    size_t getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); }
-    size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
+    unsigned getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); }
+    unsigned getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
 
     void scrollIntoView(bool alignToTop = true);
     void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
@@ -329,7 +331,7 @@
     void removeAttribute(const AtomicString& name);
     void removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
 
-    PassRefPtr<Attr> detachAttribute(size_t index);
+    PassRefPtr<Attr> detachAttribute(unsigned index);
 
     PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
     PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
@@ -684,9 +686,9 @@
     virtual NodeType nodeType() const;
     virtual bool childTypeAllowed(NodeType) const;
 
-    void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
+    void setAttributeInternal(unsigned index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
     void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
-    void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
+    void removeAttributeInternal(unsigned index, SynchronizationOfLazyAttribute);
     void attributeChangedFromParserOrByCloning(const QualifiedName&, const AtomicString&, AttributeModificationReason);
 
 #ifndef NDEBUG
@@ -863,7 +865,7 @@
     return elementData()->classNames();
 }
 
-inline size_t Element::attributeCount() const
+inline unsigned Element::attributeCount() const
 {
     ASSERT(elementData());
     return elementData()->length();
@@ -933,7 +935,7 @@
     return node && node->isElementNode() && toElement(node)->shadow();
 }
 
-inline size_t ElementData::length() const
+inline unsigned ElementData::length() const
 {
     if (isUnique())
         return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
@@ -956,25 +958,25 @@
 
 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
 {
-    size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
-    if (index != notFound)
+    unsigned index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
+    if (index != attributeNotFound)
         return attributeItem(index);
     return 0;
 }
 
-inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name) const
+inline unsigned ElementData::getAttributeItemIndex(const QualifiedName& name) const
 {
     const Attribute* attributes = attributeBase();
     for (unsigned i = 0, count = length(); i < count; ++i) {
         if (attributes[i].name().matches(name))
             return i;
     }
-    return notFound;
+    return attributeNotFound;
 }
 
 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller
 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
-inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
+inline unsigned ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
 {
     const Attribute* attributes = attributeBase();
     bool doSlowCheck = shouldIgnoreAttributeCase;
@@ -991,7 +993,7 @@
 
     if (doSlowCheck)
         return getAttributeItemIndexSlowCase(name, shouldIgnoreAttributeCase);
-    return notFound;
+    return attributeNotFound;
 }
 
 inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const

Modified: trunk/Source/WebCore/dom/NamedNodeMap.cpp (149060 => 149061)


--- trunk/Source/WebCore/dom/NamedNodeMap.cpp	2013-04-24 20:00:44 UTC (rev 149060)
+++ trunk/Source/WebCore/dom/NamedNodeMap.cpp	2013-04-24 20:03:12 UTC (rev 149061)
@@ -62,8 +62,8 @@
 
 PassRefPtr<Node> NamedNodeMap::removeNamedItem(const AtomicString& name, ExceptionCode& ec)
 {
-    size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(name, shouldIgnoreAttributeCase(m_element)) : notFound;
-    if (index == notFound) {
+    unsigned index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(name, shouldIgnoreAttributeCase(m_element)) : ElementData::attributeNotFound;
+    if (index == ElementData::attributeNotFound) {
         ec = NOT_FOUND_ERR;
         return 0;
     }
@@ -72,8 +72,8 @@
 
 PassRefPtr<Node> NamedNodeMap::removeNamedItemNS(const AtomicString& namespaceURI, const AtomicString& localName, ExceptionCode& ec)
 {
-    size_t index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(QualifiedName(nullAtom, localName, namespaceURI)) : notFound;
-    if (index == notFound) {
+    unsigned index = m_element->hasAttributes() ? m_element->getAttributeItemIndex(QualifiedName(nullAtom, localName, namespaceURI)) : notFound;
+    if (index == ElementData::attributeNotFound) {
         ec = NOT_FOUND_ERR;
         return 0;
     }
@@ -108,7 +108,7 @@
     return m_element->ensureAttr(m_element->attributeItem(index)->name());
 }
 
-size_t NamedNodeMap::length() const
+unsigned NamedNodeMap::length() const
 {
     if (!m_element->hasAttributes())
         return 0;

Modified: trunk/Source/WebCore/dom/NamedNodeMap.h (149060 => 149061)


--- trunk/Source/WebCore/dom/NamedNodeMap.h	2013-04-24 20:00:44 UTC (rev 149060)
+++ trunk/Source/WebCore/dom/NamedNodeMap.h	2013-04-24 20:03:12 UTC (rev 149061)
@@ -61,7 +61,7 @@
     PassRefPtr<Node> setNamedItemNS(Node*, ExceptionCode&);
 
     PassRefPtr<Node> item(unsigned index) const;
-    size_t length() const;
+    unsigned length() const;
 
     Element* element() const { return m_element; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to