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

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

Issue 337753005: Make iterator for Element's attributes more lightweight (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Proper rebase 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.idl ('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 b2a6169bc2a7aa6af3a7e10aa914fbd1bbeb93c1..0a8cc6202a0caad1b355b8b817cfb96887f007a9 100644
--- a/Source/core/dom/ElementData.h
+++ b/Source/core/dom/ElementData.h
@@ -43,36 +43,17 @@ class ShareableElementData;
class StylePropertySet;
class UniqueElementData;
-class AttributeConstIterator {
+class AttributeCollection {
public:
- AttributeConstIterator(const Attribute* array, unsigned index)
- : m_array(array)
- , m_index(index)
- { }
-
- const Attribute* operator*() const { return &m_array[m_index]; }
- const Attribute* operator->() const { return &m_array[m_index]; }
- AttributeConstIterator& operator++() { ++m_index; return *this; }
-
- bool operator==(const AttributeConstIterator& other) const { return m_index == other.m_index; }
- bool operator!=(const AttributeConstIterator& other) const { return !(*this == other); }
-
- unsigned index() const { return m_index; }
+ typedef const Attribute* const_iterator;
-private:
- const Attribute* m_array;
- unsigned m_index;
-};
-
-class AttributeIteratorAccessor {
-public:
- AttributeIteratorAccessor(const Attribute* array, unsigned size)
+ AttributeCollection(const Attribute* array, unsigned size)
: m_array(array)
, m_size(size)
{ }
- AttributeConstIterator begin() const { return AttributeConstIterator(m_array, 0); }
- AttributeConstIterator end() const { return AttributeConstIterator(m_array, m_size); }
+ const_iterator begin() const { return m_array; }
+ const_iterator end() const { return m_array + m_size; }
unsigned size() const { return m_size; }
@@ -105,7 +86,7 @@ public:
size_t attributeCount() const;
bool hasAttributes() const { return !!attributeCount(); }
- AttributeIteratorAccessor attributesIterator() const;
+ AttributeCollection attributes() const;
const Attribute& attributeAt(unsigned index) const;
const Attribute* findAttributeByName(const QualifiedName&) const;
@@ -243,11 +224,12 @@ inline const Attribute* ElementData::attributeBase() const
inline size_t ElementData::findAttributeIndexByName(const QualifiedName& name, bool shouldIgnoreCase) const
{
- AttributeIteratorAccessor attributes = attributesIterator();
- AttributeConstIterator end = attributes.end();
- for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
+ 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 it.index();
+ return index;
}
return kNotFound;
}
@@ -259,14 +241,15 @@ inline size_t ElementData::findAttributeIndexByName(const AtomicString& name, bo
bool doSlowCheck = shouldIgnoreAttributeCase;
// Optimize for the case where the attribute exists and its name exactly matches.
- AttributeIteratorAccessor attributes = attributesIterator();
- AttributeConstIterator end = attributes.end();
- for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
+ 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 it.index();
+ return index;
} else {
doSlowCheck = true;
}
@@ -277,22 +260,22 @@ inline size_t ElementData::findAttributeIndexByName(const AtomicString& name, bo
return kNotFound;
}
-inline AttributeIteratorAccessor ElementData::attributesIterator() const
+inline AttributeCollection ElementData::attributes() const
{
if (isUnique()) {
const Vector<Attribute, 4>& attributeVector = static_cast<const UniqueElementData*>(this)->m_attributeVector;
- return AttributeIteratorAccessor(attributeVector.data(), attributeVector.size());
+ return AttributeCollection(attributeVector.data(), attributeVector.size());
}
- return AttributeIteratorAccessor(static_cast<const ShareableElementData*>(this)->m_attributeArray, m_arraySize);
+ return AttributeCollection(static_cast<const ShareableElementData*>(this)->m_attributeArray, m_arraySize);
}
inline const Attribute* ElementData::findAttributeByName(const QualifiedName& name) const
{
- AttributeIteratorAccessor attributes = attributesIterator();
- AttributeConstIterator end = attributes.end();
- for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
+ 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 it;
}
return 0;
}
« no previous file with comments | « Source/core/dom/Element.idl ('k') | Source/core/dom/ElementData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698