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

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: 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 unsigned len = length();
189 for (unsigned i = 0; i < len; ++i) {
189 const Attribute& attribute = begin[i]; 190 const Attribute& attribute = begin[i];
190 if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase) ) 191 if (attribute.name().matchesPossiblyIgnoringCase(name, shouldIgnoreCase) )
191 return i; 192 return i;
192 } 193 }
193 return kNotFound; 194 return kNotFound;
194 } 195 }
195 196
196 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so th at the caller 197 // 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). 198 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
198 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const 199 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
199 { 200 {
200 unsigned len = length(); 201 unsigned len = length();
Inactive 2013/12/04 19:14:30 Note that we already cache the length in this meth
201 bool doSlowCheck = shouldIgnoreAttributeCase; 202 bool doSlowCheck = shouldIgnoreAttributeCase;
202 203
203 // Optimize for the case where the attribute exists and its name exactly mat ches. 204 // Optimize for the case where the attribute exists and its name exactly mat ches.
204 const Attribute* begin = attributeBase(); 205 const Attribute* begin = attributeBase();
205 for (unsigned i = 0; i < len; ++i) { 206 for (unsigned i = 0; i < len; ++i) {
206 const Attribute& attribute = begin[i]; 207 const Attribute& attribute = begin[i];
207 if (!attribute.name().hasPrefix()) { 208 if (!attribute.name().hasPrefix()) {
208 if (name == attribute.localName()) 209 if (name == attribute.localName())
209 return i; 210 return i;
210 } else { 211 } else {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 246 }
246 247
247 inline Attribute* UniqueElementData::attributeItem(unsigned index) 248 inline Attribute* UniqueElementData::attributeItem(unsigned index)
248 { 249 {
249 return &m_attributeVector.at(index); 250 return &m_attributeVector.at(index);
250 } 251 }
251 252
252 } // namespace WebCore 253 } // namespace WebCore
253 254
254 #endif // ElementData_h 255 #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