Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Unified Diff: Source/core/dom/ElementData.h

Issue 354023008: Move attributes-related methods from ElementData to AttributeCollection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ElementData.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ElementData.h
diff --git a/Source/core/dom/ElementData.h b/Source/core/dom/ElementData.h
index 99aa0123d074c0ec6182030440abc15403adbd73..051cc65aa8d6cb298b24fcd9f821ae82bbdf1a5b 100644
--- a/Source/core/dom/ElementData.h
+++ b/Source/core/dom/ElementData.h
@@ -33,36 +33,17 @@
#define ElementData_h
#include "core/dom/Attribute.h"
+#include "core/dom/AttributeCollection.h"
#include "core/dom/SpaceSplitString.h"
#include "platform/heap/Handle.h"
#include "wtf/text/AtomicString.h"
namespace WebCore {
-class Attr;
class ShareableElementData;
class StylePropertySet;
class UniqueElementData;
-class AttributeCollection {
-public:
- typedef const Attribute* const_iterator;
-
- AttributeCollection(const Attribute* array, unsigned size)
- : m_array(array)
- , m_size(size)
- { }
-
- const_iterator begin() const { return m_array; }
- const_iterator end() const { return m_array + m_size; }
-
- unsigned size() const { return m_size; }
-
-private:
- const Attribute* m_array;
- unsigned m_size;
-};
-
// ElementData represents very common, but not necessarily unique to an element,
// data such as attributes, inline style, and parsed class names and ids.
class ElementData : public RefCountedWillBeGarbageCollectedFinalized<ElementData> {
@@ -89,18 +70,8 @@ public:
const StylePropertySet* presentationAttributeStyle() const;
- // This is not a trivial getter and its return value should be cached for performance.
- size_t attributeCount() const;
- bool hasAttributes() const { return !!attributeCount(); }
-
AttributeCollection attributes() const;
- const Attribute& attributeAt(unsigned index) const;
- const Attribute* findAttributeByName(const QualifiedName&) const;
- size_t findAttributeIndexByName(const QualifiedName&, bool shouldIgnoreCase = false) const;
- size_t findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
- size_t findAttrNodeIndex(Attr*) const;
-
bool hasID() const { return !m_idForStyleResolution.isNull(); }
bool hasClass() const { return !m_classNames.isNull(); }
@@ -137,10 +108,6 @@ private:
void destroy();
#endif
- const Attribute* attributeBase() const;
- const Attribute* findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
- size_t findAttributeIndexByNameSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
-
PassRefPtrWillBeRawPtr<UniqueElementData> makeUniqueCopy() const;
};
@@ -173,6 +140,8 @@ public:
return location;
}
+ AttributeCollection attributes() const;
+
Attribute m_attributeArray[0];
};
@@ -195,6 +164,8 @@ public:
void appendAttribute(const QualifiedName&, const AtomicString&);
void removeAttributeAt(size_t index);
+ AttributeCollection attributes() const;
+
Attribute& attributeAt(unsigned index);
Attribute* findAttributeByName(const QualifiedName&);
@@ -221,13 +192,6 @@ inline void ElementData::deref()
}
#endif
-inline size_t ElementData::attributeCount() const
-{
- if (isUnique())
- return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
- return m_arraySize;
-}
-
inline const StylePropertySet* ElementData::presentationAttributeStyle() const
{
if (!m_isUnique)
@@ -235,84 +199,21 @@ inline const StylePropertySet* ElementData::presentationAttributeStyle() const
return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();
}
-inline const Attribute* ElementData::findAttributeByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const
-{
- size_t index = findAttributeIndexByName(name, shouldIgnoreAttributeCase);
- if (index != kNotFound)
- return &attributeAt(index);
- return 0;
-}
-
-inline const Attribute* ElementData::attributeBase() const
-{
- if (m_isUnique)
- return static_cast<const UniqueElementData*>(this)->m_attributeVector.begin();
- return static_cast<const ShareableElementData*>(this)->m_attributeArray;
-}
-
-inline size_t ElementData::findAttributeIndexByName(const QualifiedName& name, bool shouldIgnoreCase) const
-{
- AttributeCollection attributes = this->attributes();
- AttributeCollection::const_iterator end = attributes.end();
- unsigned index = 0;
- for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it, ++index) {
- if (it->name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase))
- return index;
- }
- return kNotFound;
-}
-
-// 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::findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const
-{
- bool doSlowCheck = shouldIgnoreAttributeCase;
-
- // Optimize for the case where the attribute exists and its name exactly matches.
- AttributeCollection attributes = this->attributes();
- AttributeCollection::const_iterator end = attributes.end();
- unsigned index = 0;
- for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it, ++index) {
- // FIXME: Why check the prefix? Namespaces should be all that matter.
- // Most attributes (all of HTML and CSS) have no namespace.
- if (!it->name().hasPrefix()) {
- if (name == it->localName())
- return index;
- } else {
- doSlowCheck = true;
- }
- }
-
- if (doSlowCheck)
- return findAttributeIndexByNameSlowCase(name, shouldIgnoreAttributeCase);
- return kNotFound;
-}
-
inline AttributeCollection ElementData::attributes() const
{
- if (isUnique()) {
- const Vector<Attribute, 4>& attributeVector = static_cast<const UniqueElementData*>(this)->m_attributeVector;
- return AttributeCollection(attributeVector.data(), attributeVector.size());
- }
- return AttributeCollection(static_cast<const ShareableElementData*>(this)->m_attributeArray, m_arraySize);
+ if (isUnique())
+ return static_cast<const UniqueElementData*>(this)->attributes();
+ return static_cast<const ShareableElementData*>(this)->attributes();
}
-inline const Attribute* ElementData::findAttributeByName(const QualifiedName& name) const
+inline AttributeCollection ShareableElementData::attributes() const
{
- AttributeCollection attributes = this->attributes();
- AttributeCollection::const_iterator end = attributes.end();
- for (AttributeCollection::const_iterator it = attributes.begin(); it != end; ++it) {
- if (it->name().matches(name))
- return it;
- }
- return 0;
+ return AttributeCollection(m_attributeArray, m_arraySize);
}
-inline const Attribute& ElementData::attributeAt(unsigned index) const
+inline AttributeCollection UniqueElementData::attributes() const
{
- RELEASE_ASSERT(index < attributeCount());
- ASSERT(attributeBase() + index);
- return *(attributeBase() + index);
+ return AttributeCollection(m_attributeVector.data(), m_attributeVector.size());
}
inline void UniqueElementData::appendAttribute(const QualifiedName& attributeName, const AtomicString& value)
« no previous file with comments | « Source/core/dom/Element.cpp ('k') | Source/core/dom/ElementData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698