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

Side by Side Diff: Source/core/dom/Element.cpp

Issue 298253009: Add iterator object to iterate efficiently over an Element's attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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
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 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 1226
1227 m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix); 1227 m_tagName.setPrefix(prefix.isEmpty() ? AtomicString() : prefix);
1228 } 1228 }
1229 1229
1230 const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace ToLocate) const 1230 const AtomicString& Element::locateNamespacePrefix(const AtomicString& namespace ToLocate) const
1231 { 1231 {
1232 if (!prefix().isNull() && namespaceURI() == namespaceToLocate) 1232 if (!prefix().isNull() && namespaceURI() == namespaceToLocate)
1233 return prefix(); 1233 return prefix();
1234 1234
1235 if (hasAttributes()) { 1235 if (hasAttributes()) {
1236 unsigned attributeCount = this->attributeCount(); 1236 AttributeIteratorAccessor attributes = attributesIterator();
1237 for (unsigned i = 0; i < attributeCount; ++i) { 1237 AttributeConstIterator end = attributes.end();
1238 const Attribute& attr = attributeItem(i); 1238 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
1239 1239 if (it->prefix() == xmlnsAtom && it->value() == namespaceToLocate)
1240 if (attr.prefix() == xmlnsAtom && attr.value() == namespaceToLocate) 1240 return it->localName();
1241 return attr.localName();
1242 } 1241 }
1243 } 1242 }
1244 1243
1245 if (Element* parent = parentElement()) 1244 if (Element* parent = parentElement())
1246 return parent->locateNamespacePrefix(namespaceToLocate); 1245 return parent->locateNamespacePrefix(namespaceToLocate);
1247 1246
1248 return nullAtom; 1247 return nullAtom;
1249 } 1248 }
1250 1249
1251 KURL Element::baseURI() const 1250 KURL Element::baseURI() const
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 } 2979 }
2981 } 2980 }
2982 ASSERT_NOT_REACHED(); 2981 ASSERT_NOT_REACHED();
2983 } 2982 }
2984 2983
2985 void Element::detachAllAttrNodesFromElement() 2984 void Element::detachAllAttrNodesFromElement()
2986 { 2985 {
2987 AttrNodeList* attrNodeList = attrNodeListForElement(this); 2986 AttrNodeList* attrNodeList = attrNodeListForElement(this);
2988 ASSERT(attrNodeList); 2987 ASSERT(attrNodeList);
2989 2988
2990 unsigned attributeCount = this->attributeCount(); 2989 AttributeIteratorAccessor attributes = attributesIterator();
2991 for (unsigned i = 0; i < attributeCount; ++i) { 2990 AttributeConstIterator end = attributes.end();
2992 const Attribute& attribute = attributeItem(i); 2991 for (AttributeConstIterator it = attributes.begin(); it != end; ++it) {
2993 if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList , attribute.name())) 2992 if (RefPtrWillBeRawPtr<Attr> attrNode = findAttrNodeInList(*attrNodeList , it->name()))
2994 attrNode->detachFromElementWithValue(attribute.value()); 2993 attrNode->detachFromElementWithValue(it->value());
2995 } 2994 }
2996 2995
2997 removeAttrNodeListForElement(this); 2996 removeAttrNodeListForElement(this);
2998 } 2997 }
2999 2998
3000 void Element::willRecalcStyle(StyleRecalcChange) 2999 void Element::willRecalcStyle(StyleRecalcChange)
3001 { 3000 {
3002 ASSERT(hasCustomStyleCallbacks()); 3001 ASSERT(hasCustomStyleCallbacks());
3003 } 3002 }
3004 3003
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3048 if (other.m_elementData->isUnique() 3047 if (other.m_elementData->isUnique()
3049 && !ownerDocumentsHaveDifferentCaseSensitivity 3048 && !ownerDocumentsHaveDifferentCaseSensitivity
3050 && !other.m_elementData->presentationAttributeStyle()) 3049 && !other.m_elementData->presentationAttributeStyle())
3051 const_cast<Element&>(other).m_elementData = static_cast<const UniqueElem entData*>(other.m_elementData.get())->makeShareableCopy(); 3050 const_cast<Element&>(other).m_elementData = static_cast<const UniqueElem entData*>(other.m_elementData.get())->makeShareableCopy();
3052 3051
3053 if (!other.m_elementData->isUnique() && !ownerDocumentsHaveDifferentCaseSens itivity && !needsURLResolutionForInlineStyle(other, other.document(), document() )) 3052 if (!other.m_elementData->isUnique() && !ownerDocumentsHaveDifferentCaseSens itivity && !needsURLResolutionForInlineStyle(other, other.document(), document() ))
3054 m_elementData = other.m_elementData; 3053 m_elementData = other.m_elementData;
3055 else 3054 else
3056 m_elementData = other.m_elementData->makeUniqueCopy(); 3055 m_elementData = other.m_elementData->makeUniqueCopy();
3057 3056
3058 unsigned length = m_elementData->length(); 3057 AttributeIteratorAccessor attributes = m_elementData->attributesIterator();
3059 for (unsigned i = 0; i < length; ++i) { 3058 AttributeConstIterator end = attributes.end();
3060 const Attribute& attribute = m_elementData->attributeItem(i); 3059 for (AttributeConstIterator it = attributes.begin(); it != end; ++it)
3061 attributeChangedFromParserOrByCloning(attribute.name(), attribute.value( ), ModifiedByCloning); 3060 attributeChangedFromParserOrByCloning(it->name(), it->value(), ModifiedB yCloning);
3062 }
3063 } 3061 }
3064 3062
3065 void Element::cloneDataFromElement(const Element& other) 3063 void Element::cloneDataFromElement(const Element& other)
3066 { 3064 {
3067 cloneAttributesFromElement(other); 3065 cloneAttributesFromElement(other);
3068 copyNonAttributePropertiesFromElement(other); 3066 copyNonAttributePropertiesFromElement(other);
3069 } 3067 }
3070 3068
3071 void Element::createUniqueElementData() 3069 void Element::createUniqueElementData()
3072 { 3070 {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
3299 3297
3300 void Element::trace(Visitor* visitor) 3298 void Element::trace(Visitor* visitor)
3301 { 3299 {
3302 if (hasRareData()) 3300 if (hasRareData())
3303 visitor->trace(elementRareData()); 3301 visitor->trace(elementRareData());
3304 3302
3305 ContainerNode::trace(visitor); 3303 ContainerNode::trace(visitor);
3306 } 3304 }
3307 3305
3308 } // namespace WebCore 3306 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698