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

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

Issue 105163003: Cache length in ElementData::getAttributeItemIndex() for performance (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add comments Created 7 years 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 | « no previous file | no next file » | 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 b7c36f097a53720d0e80ec561c4a7e6ceb3c81ff..a5ffabf0964116ed689aa6706aceb07d62469c2a 100644
--- a/Source/core/dom/ElementData.h
+++ b/Source/core/dom/ElementData.h
@@ -185,7 +185,9 @@ inline const Attribute* ElementData::attributeBase() const
inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool shouldIgnoreCase) const
{
const Attribute* begin = attributeBase();
- for (unsigned i = 0; i < length(); ++i) {
+ // Cache length for performance as ElementData::length() contains a conditional branch.
+ unsigned len = length();
+ for (unsigned i = 0; i < len; ++i) {
const Attribute& attribute = begin[i];
if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase))
return i;
@@ -197,6 +199,7 @@ inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool
// can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
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();
bool doSlowCheck = shouldIgnoreAttributeCase;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698