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

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

Issue 177613003: Consistently cache ElementData::length() before loops (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix test failure Created 6 years, 10 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.h ('k') | Source/core/dom/ElementData.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index aaf9cf83c96d74f097ffa568dc2c566ebdbed5e5..af6ec4018990f8363d96dbde48eefabef4bc78c2 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -1248,7 +1248,8 @@ const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace
return prefix();
if (hasAttributes()) {
- for (unsigned i = 0; i < attributeCount(); i++) {
+ unsigned attributeCount = this->attributeCount();
+ for (unsigned i = 0; i < attributeCount; ++i) {
const Attribute* attr = attributeItem(i);
if (attr->prefix() == xmlnsAtom && attr->value() == namespaceToLocate)
@@ -2691,6 +2692,8 @@ void Element::normalizeAttributes()
{
if (!hasAttributes())
return;
+ // attributeCount() cannot be cached before the loop because the attributes
+ // list is altered while iterating.
for (unsigned i = 0; i < attributeCount(); ++i) {
if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
attr->normalize();
@@ -3179,7 +3182,8 @@ void Element::detachAllAttrNodesFromElement()
AttrNodeList* attrNodeList = attrNodeListForElement(this);
ASSERT(attrNodeList);
- for (unsigned i = 0; i < attributeCount(); ++i) {
+ unsigned attributeCount = this->attributeCount();
+ for (unsigned i = 0; i < attributeCount; ++i) {
const Attribute* attribute = attributeItem(i);
if (RefPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, attribute->name()))
attrNode->detachFromElementWithValue(attribute->value());
@@ -3246,7 +3250,8 @@ void Element::cloneAttributesFromElement(const Element& other)
else
m_elementData = other.m_elementData->makeUniqueCopy();
- for (unsigned i = 0; i < m_elementData->length(); ++i) {
+ unsigned length = m_elementData->length();
+ for (unsigned i = 0; i < length; ++i) {
const Attribute* attribute = const_cast<const ElementData*>(m_elementData.get())->attributeItem(i);
attributeChangedFromParserOrByCloning(attribute->name(), attribute->value(), ModifiedByCloning);
}
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698