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

Unified Diff: Source/core/dom/Element.cpp

Issue 298253009: Add iterator object to iterate efficiently over an Element's attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 6fda57079b921222b9414a5b413edf4afd405399..2cdd389404066a0152d229d2ab87ba10aedca84d 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -1233,12 +1233,11 @@ const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace
return prefix();
if (hasAttributes()) {
- unsigned attributeCount = this->attributeCount();
- for (unsigned i = 0; i < attributeCount; ++i) {
- const Attribute& attr = attributeItem(i);
-
- if (attr.prefix() == xmlnsAtom && attr.value() == namespaceToLocate)
- return attr.localName();
+ AttributeIteratorAccessor attributes = attributesIterator();
+ AttributeConstIterator end = attributes.end();
+ for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
+ if (it->prefix() == xmlnsAtom && it->value() == namespaceToLocate)
+ return it->localName();
}
}
@@ -2987,11 +2986,11 @@ void Element::detachAllAttrNodesFromElement()
AttrNodeList* attrNodeList = attrNodeListForElement(this);
ASSERT(attrNodeList);
- unsigned attributeCount = this->attributeCount();
- for (unsigned i = 0; i < attributeCount; ++i) {
- const Attribute& attribute = attributeItem(i);
- if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, attribute.name()))
- attrNode->detachFromElementWithValue(attribute.value());
+ AttributeIteratorAccessor attributes = attributesIterator();
+ AttributeConstIterator end = attributes.end();
+ for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
+ if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, it->name()))
+ attrNode->detachFromElementWithValue(it->value());
}
removeAttrNodeListForElement(this);
@@ -3055,11 +3054,10 @@ void Element::cloneAttributesFromElement(const Element& other)
else
m_elementData = other.m_elementData->makeUniqueCopy();
- unsigned length = m_elementData->length();
- for (unsigned i = 0; i < length; ++i) {
- const Attribute& attribute = m_elementData->attributeItem(i);
- attributeChangedFromParserOrByCloning(attribute.name(), attribute.value(), ModifiedByCloning);
- }
+ AttributeIteratorAccessor attributes = m_elementData->attributesIterator();
+ AttributeConstIterator end = attributes.end();
+ for (AttributeConstIterator it = attributes.begin(); it != end; ++it)
+ attributeChangedFromParserOrByCloning(it->name(), it->value(), ModifiedByCloning);
}
void Element::cloneDataFromElement(const Element& other)

Powered by Google App Engine
This is Rietveld 408576698