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

Side by Side Diff: Source/core/dom/Element.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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementData.h » ('j') | 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 1241
1242 m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix); 1242 m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix);
1243 } 1243 }
1244 1244
1245 const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace ToLocate) const 1245 const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace ToLocate) const
1246 { 1246 {
1247 if (!prefix().isNull() && namespaceURI() == namespaceToLocate) 1247 if (!prefix().isNull() && namespaceURI() == namespaceToLocate)
1248 return prefix(); 1248 return prefix();
1249 1249
1250 if (hasAttributes()) { 1250 if (hasAttributes()) {
1251 for (unsigned i = 0; i < attributeCount(); i++) { 1251 unsigned attributeCount = this->attributeCount();
1252 for (unsigned i = 0; i < attributeCount; ++i) {
1252 const Attribute* attr = attributeItem(i); 1253 const Attribute* attr = attributeItem(i);
1253 1254
1254 if (attr->prefix() == xmlnsAtom && attr->value() == namespaceToLocat e) 1255 if (attr->prefix() == xmlnsAtom && attr->value() == namespaceToLocat e)
1255 return attr->localName(); 1256 return attr->localName();
1256 } 1257 }
1257 } 1258 }
1258 1259
1259 if (Element* parent = parentElement()) 1260 if (Element* parent = parentElement())
1260 return parent->locateNamespacePrefix(namespaceToLocate); 1261 return parent->locateNamespacePrefix(namespaceToLocate);
1261 1262
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 if (hasRareData()) 2685 if (hasRareData())
2685 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false); 2686 elementRareData()->setNeedsFocusAppearanceUpdateSoonAfterAttach(false);
2686 if (document().focusedElement() == this) 2687 if (document().focusedElement() == this)
2687 document().cancelFocusAppearanceUpdate(); 2688 document().cancelFocusAppearanceUpdate();
2688 } 2689 }
2689 2690
2690 void Element::normalizeAttributes() 2691 void Element::normalizeAttributes()
2691 { 2692 {
2692 if (!hasAttributes()) 2693 if (!hasAttributes())
2693 return; 2694 return;
2695 // attributeCount() cannot be cached before the loop because the attributes
2696 // list is altered while iterating.
2694 for (unsigned i = 0; i < attributeCount(); ++i) { 2697 for (unsigned i = 0; i < attributeCount(); ++i) {
2695 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name())) 2698 if (RefPtr<Attr> attr = attrIfExists(attributeItem(i)->name()))
2696 attr->normalize(); 2699 attr->normalize();
2697 } 2700 }
2698 } 2701 }
2699 2702
2700 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change) 2703 void Element::updatePseudoElement(PseudoId pseudoId, StyleRecalcChange change)
2701 { 2704 {
2702 ASSERT(!needsStyleRecalc()); 2705 ASSERT(!needsStyleRecalc());
2703 PseudoElement* element = pseudoElement(pseudoId); 2706 PseudoElement* element = pseudoElement(pseudoId);
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
3172 } 3175 }
3173 } 3176 }
3174 ASSERT_NOT_REACHED(); 3177 ASSERT_NOT_REACHED();
3175 } 3178 }
3176 3179
3177 void Element::detachAllAttrNodesFromElement() 3180 void Element::detachAllAttrNodesFromElement()
3178 { 3181 {
3179 AttrNodeList* attrNodeList = attrNodeListForElement(this); 3182 AttrNodeList* attrNodeList = attrNodeListForElement(this);
3180 ASSERT(attrNodeList); 3183 ASSERT(attrNodeList);
3181 3184
3182 for (unsigned i = 0; i < attributeCount(); ++i) { 3185 unsigned attributeCount = this->attributeCount();
3186 for (unsigned i = 0; i < attributeCount; ++i) {
3183 const Attribute* attribute = attributeItem(i); 3187 const Attribute* attribute = attributeItem(i);
3184 if (RefPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, attribute- >name())) 3188 if (RefPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList, attribute- >name()))
3185 attrNode->detachFromElementWithValue(attribute->value()); 3189 attrNode->detachFromElementWithValue(attribute->value());
3186 } 3190 }
3187 3191
3188 removeAttrNodeListForElement(this); 3192 removeAttrNodeListForElement(this);
3189 } 3193 }
3190 3194
3191 void Element::willRecalcStyle(StyleRecalcChange) 3195 void Element::willRecalcStyle(StyleRecalcChange)
3192 { 3196 {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3239 if (other.m_elementData->isUnique() 3243 if (other.m_elementData->isUnique()
3240 && !ownerDocumentsHaveDifferentCaseSensitivity 3244 && !ownerDocumentsHaveDifferentCaseSensitivity
3241 && !other.m_elementData->presentationAttributeStyle()) 3245 && !other.m_elementData->presentationAttributeStyle())
3242 const_cast<Element&>(other).m_elementData = static_cast<const UniqueElem entData*>(other.m_elementData.get())->makeShareableCopy(); 3246 const_cast<Element&>(other).m_elementData = static_cast<const UniqueElem entData*>(other.m_elementData.get())->makeShareableCopy();
3243 3247
3244 if (!other.m_elementData->isUnique() && !ownerDocumentsHaveDifferentCaseSens itivity) 3248 if (!other.m_elementData->isUnique() && !ownerDocumentsHaveDifferentCaseSens itivity)
3245 m_elementData = other.m_elementData; 3249 m_elementData = other.m_elementData;
3246 else 3250 else
3247 m_elementData = other.m_elementData->makeUniqueCopy(); 3251 m_elementData = other.m_elementData->makeUniqueCopy();
3248 3252
3249 for (unsigned i = 0; i < m_elementData->length(); ++i) { 3253 unsigned length = m_elementData->length();
3254 for (unsigned i = 0; i < length; ++i) {
3250 const Attribute* attribute = const_cast<const ElementData*>(m_elementDat a.get())->attributeItem(i); 3255 const Attribute* attribute = const_cast<const ElementData*>(m_elementDat a.get())->attributeItem(i);
3251 attributeChangedFromParserOrByCloning(attribute->name(), attribute->valu e(), ModifiedByCloning); 3256 attributeChangedFromParserOrByCloning(attribute->name(), attribute->valu e(), ModifiedByCloning);
3252 } 3257 }
3253 } 3258 }
3254 3259
3255 void Element::cloneDataFromElement(const Element& other) 3260 void Element::cloneDataFromElement(const Element& other)
3256 { 3261 {
3257 cloneAttributesFromElement(other); 3262 cloneAttributesFromElement(other);
3258 copyNonAttributePropertiesFromElement(other); 3263 copyNonAttributePropertiesFromElement(other);
3259 } 3264 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
3504 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems 3509 // Before doing so, we need to resolve issues in HTMLSelectElement::recalcLi stItems
3505 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405 3510 // and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cg i?id=88405
3506 if (hasTagName(optionTag) || hasTagName(optgroupTag)) 3511 if (hasTagName(optionTag) || hasTagName(optgroupTag))
3507 return false; 3512 return false;
3508 if (FullscreenElementStack::isActiveFullScreenElement(this)) 3513 if (FullscreenElementStack::isActiveFullScreenElement(this))
3509 return false; 3514 return false;
3510 return true; 3515 return true;
3511 } 3516 }
3512 3517
3513 } // namespace WebCore 3518 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/Element.h ('k') | Source/core/dom/ElementData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698