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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 inline const Attribute* ElementData::attributeBase() const 178 inline const Attribute* ElementData::attributeBase() const
179 { 179 {
180 if (m_isUnique) 180 if (m_isUnique)
181 return static_cast<const UniqueElementData*>(this)->m_attributeVector.be gin(); 181 return static_cast<const UniqueElementData*>(this)->m_attributeVector.be gin();
182 return static_cast<const ShareableElementData*>(this)->m_attributeArray; 182 return static_cast<const ShareableElementData*>(this)->m_attributeArray;
183 } 183 }
184 184
185 inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool shouldIgnoreCase) const 185 inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name, bool shouldIgnoreCase) const
186 { 186 {
187 const Attribute* begin = attributeBase(); 187 const Attribute* begin = attributeBase();
188 for (unsigned i = 0; i < length(); ++i) { 188 // Cache length for performance as ElementData::length() contains a conditio nal branch.
189 unsigned len = length();
190 for (unsigned i = 0; i < len; ++i) {
189 const Attribute& attribute = begin[i]; 191 const Attribute& attribute = begin[i];
190 if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase) ) 192 if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase) )
191 return i; 193 return i;
192 } 194 }
193 return kNotFound; 195 return kNotFound;
194 } 196 }
195 197
196 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so th at the caller 198 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so th at the caller
197 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not). 199 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
198 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const 200 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
199 { 201 {
202 // Cache length for performance as ElementData::length() contains a conditio nal branch.
200 unsigned len = length(); 203 unsigned len = length();
201 bool doSlowCheck = shouldIgnoreAttributeCase; 204 bool doSlowCheck = shouldIgnoreAttributeCase;
202 205
203 // Optimize for the case where the attribute exists and its name exactly mat ches. 206 // Optimize for the case where the attribute exists and its name exactly mat ches.
204 const Attribute* begin = attributeBase(); 207 const Attribute* begin = attributeBase();
205 for (unsigned i = 0; i < len; ++i) { 208 for (unsigned i = 0; i < len; ++i) {
206 const Attribute& attribute = begin[i]; 209 const Attribute& attribute = begin[i];
207 if (!attribute.name().hasPrefix()) { 210 if (!attribute.name().hasPrefix()) {
208 if (name == attribute.localName()) 211 if (name == attribute.localName())
209 return i; 212 return i;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 248 }
246 249
247 inline Attribute* UniqueElementData::attributeItem(unsigned index) 250 inline Attribute* UniqueElementData::attributeItem(unsigned index)
248 { 251 {
249 return &m_attributeVector.at(index); 252 return &m_attributeVector.at(index);
250 } 253 }
251 254
252 } // namespace WebCore 255 } // namespace WebCore
253 256
254 #endif // ElementData_h 257 #endif // ElementData_h
OLDNEW
« 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