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

Unified Diff: Source/core/dom/ElementData.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/ElementData.h ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ElementData.cpp
diff --git a/Source/core/dom/ElementData.cpp b/Source/core/dom/ElementData.cpp
index 15dd984c7baab32786709e009456d8db5da66355..2cff71fc531461b532f7e88af58ce8febf7a54d9 100644
--- a/Source/core/dom/ElementData.cpp
+++ b/Source/core/dom/ElementData.cpp
@@ -100,11 +100,11 @@ bool ElementData::isEquivalent(const ElementData* other) const
if (!other)
return isEmpty();
- unsigned len = length();
- if (len != other->length())
+ unsigned length = this->length();
+ if (length != other->length())
return false;
- for (unsigned i = 0; i < len; i++) {
+ for (unsigned i = 0; i < length; ++i) {
const Attribute* attribute = attributeItem(i);
const Attribute* otherAttr = other->getAttributeItem(attribute->name());
if (!otherAttr || attribute->value() != otherAttr->value())
@@ -117,7 +117,8 @@ bool ElementData::isEquivalent(const ElementData* other) const
size_t ElementData::getAttrIndex(Attr* attr) const
{
// This relies on the fact that Attr's QualifiedName == the Attribute's name.
- for (unsigned i = 0; i < length(); ++i) {
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
if (attributeItem(i)->name() == attr->qualifiedName())
return i;
}
@@ -127,7 +128,8 @@ size_t ElementData::getAttrIndex(Attr* attr) const
size_t 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) {
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
const Attribute* attribute = attributeItem(i);
// FIXME: Why check the prefix? Namespace is all that should matter
// and all HTML/SVG attributes have a null namespace!
@@ -196,8 +198,9 @@ UniqueElementData::UniqueElementData(const ShareableElementData& other)
ASSERT(!other.m_inlineStyle || !other.m_inlineStyle->isMutable());
m_inlineStyle = other.m_inlineStyle;
- m_attributeVector.reserveCapacity(other.length());
- for (unsigned i = 0; i < other.length(); ++i)
+ unsigned length = other.length();
+ m_attributeVector.reserveCapacity(length);
+ for (unsigned i = 0; i < length; ++i)
m_attributeVector.uncheckedAppend(other.m_attributeArray[i]);
}
@@ -214,7 +217,8 @@ PassRefPtr<ShareableElementData> UniqueElementData::makeShareableCopy() const
Attribute* UniqueElementData::getAttributeItem(const QualifiedName& name)
{
- for (unsigned i = 0; i < length(); ++i) {
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
if (m_attributeVector.at(i).name().matches(name))
return &m_attributeVector.at(i);
}
« no previous file with comments | « Source/core/dom/ElementData.h ('k') | Source/core/dom/Node.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698