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

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

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.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 76451f8a397742f42836e95d68b7cf80456295aa..146ad5320839836270d4585bb483c01a21dbf2bd 100644
--- a/Source/core/dom/ElementData.h
+++ b/Source/core/dom/ElementData.h
@@ -62,6 +62,7 @@ public:
const StylePropertySet* presentationAttributeStyle() const;
+ // This is not a trivial getter and its return value should be cached for performance.
size_t length() const;
bool isEmpty() const { return !length(); }
@@ -203,8 +204,8 @@ inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool
{
const Attribute* begin = attributeBase();
// Cache length for performance as ElementData::length() contains a conditional branch.
- unsigned len = length();
- for (unsigned i = 0; i < len; ++i) {
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
const Attribute& attribute = begin[i];
if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase))
return i;
@@ -217,12 +218,12 @@ inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool
inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
{
// Cache length for performance as ElementData::length() contains a conditional branch.
- unsigned len = length();
+ unsigned length = this->length();
bool doSlowCheck = shouldIgnoreAttributeCase;
// Optimize for the case where the attribute exists and its name exactly matches.
const Attribute* begin = attributeBase();
- for (unsigned i = 0; i < len; ++i) {
+ for (unsigned i = 0; i < length; ++i) {
const Attribute& attribute = begin[i];
// FIXME: Why check the prefix? Namespaces should be all that matter.
// Most attributes (all of HTML and CSS) have no namespace.
@@ -242,7 +243,8 @@ inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool
inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const
{
const Attribute* begin = attributeBase();
- for (unsigned i = 0; i < length(); ++i) {
+ unsigned length = this->length();
+ for (unsigned i = 0; i < length; ++i) {
const Attribute& attribute = begin[i];
if (attribute.name().matches(name))
return &attribute;
« 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