Changeset 109619 in webkit
- Timestamp:
- Mar 2, 2012 2:48:03 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r109612 r109619 1 2012-03-02 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 3 Implement NamedNodeMap::setNamedItem() in terms of Element::setAttributeNode() instead of the other way round 4 https://bugs.webkit.org/show_bug.cgi?id=80188 5 6 Reviewed by Ryosuke Niwa. 7 8 Using setNamedItem() in setAttributeNode() implementation made us do unnecessary 9 checks like whether the element existed or whether the given node was an 10 attribute. So now setAttributeNode() do less work. 11 12 No new tests were added, functionality should be unchanged. 13 14 * dom/Element.cpp: 15 (WebCore::Element::setAttributeNode): 16 (WebCore::Element::setAttributeNodeNS): 17 * dom/Element.h: 18 (Element): 19 (WebCore::Element::attributes): We got rid of ensureUpdatedAttributes(), next in 20 line will be updatedAttributes(). 21 * dom/NamedNodeMap.cpp: 22 (WebCore::NamedNodeMap::setNamedItem): 23 1 24 2012-03-02 SravanKumar Sandela <ssandela@innominds.com> 2 25 -
trunk/Source/WebCore/dom/Element.cpp
r109585 r109619 1375 1375 return 0; 1376 1376 } 1377 return static_pointer_cast<Attr>(ensureUpdatedAttributes()->setNamedItem(attr, ec)); 1377 1378 ElementAttributeData* attributeData = ensureUpdatedAttributeData(); 1379 Attribute* attribute = attr->attr(); 1380 size_t index = attributeData->getAttributeItemIndex(attribute->name()); 1381 Attribute* oldAttribute = index != notFound ? attributeData->attributeItem(index) : 0; 1382 if (oldAttribute == attribute) 1383 return attr; // we know about it already 1384 1385 // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object. 1386 // The DOM user must explicitly clone Attr nodes to re-use them in other elements. 1387 if (attr->ownerElement()) { 1388 ec = INUSE_ATTRIBUTE_ERR; 1389 return 0; 1390 } 1391 1392 RefPtr<Attr> oldAttr; 1393 if (oldAttribute) { 1394 oldAttr = oldAttribute->createAttrIfNeeded(this); 1395 attributeData->replaceAttribute(index, attribute, this); 1396 } else 1397 attributeData->addAttribute(attribute, this); 1398 1399 return oldAttr.release(); 1378 1400 } 1379 1401 1380 1402 PassRefPtr<Attr> Element::setAttributeNodeNS(Attr* attr, ExceptionCode& ec) 1381 1403 { 1382 if (!attr) { 1383 ec = TYPE_MISMATCH_ERR; 1384 return 0; 1385 } 1386 return static_pointer_cast<Attr>(ensureUpdatedAttributes()->setNamedItem(attr, ec)); 1404 return setAttributeNode(attr, ec); 1387 1405 } 1388 1406 -
trunk/Source/WebCore/dom/Element.h
r109585 r109619 229 229 230 230 // For exposing to DOM only. 231 NamedNodeMap* attributes() const { return ensureUpdatedAttributes(); } 232 233 NamedNodeMap* ensureUpdatedAttributes() const; 231 NamedNodeMap* attributes() const; 232 234 233 NamedNodeMap* updatedAttributes() const; 235 234 … … 531 530 } 532 531 533 inline NamedNodeMap* Element:: ensureUpdatedAttributes() const532 inline NamedNodeMap* Element::attributes() const 534 533 { 535 534 updateInvalidAttributes(); -
trunk/Source/WebCore/dom/NamedNodeMap.cpp
r109585 r109619 104 104 return 0; 105 105 } 106 Attr* attr = static_cast<Attr*>(node);107 106 108 Attribute* attribute = attr->attr(); 109 size_t index = m_attributeData.getAttributeItemIndex(attribute->name()); 110 Attribute* oldAttribute = index != notFound ? m_attributeData.attributeItem(index) : 0; 111 if (oldAttribute == attribute) 112 return node; // we know about it already 113 114 // INUSE_ATTRIBUTE_ERR: Raised if node is an Attr that is already an attribute of another Element object. 115 // The DOM user must explicitly clone Attr nodes to re-use them in other elements. 116 if (attr->ownerElement()) { 117 ec = INUSE_ATTRIBUTE_ERR; 118 return 0; 119 } 120 121 RefPtr<Attr> oldAttr; 122 if (oldAttribute) { 123 oldAttr = oldAttribute->createAttrIfNeeded(m_element); 124 m_attributeData.replaceAttribute(index, attribute, m_element); 125 } else 126 m_attributeData.addAttribute(attribute, m_element); 127 128 return oldAttr.release(); 107 return m_element->setAttributeNode(static_cast<Attr*>(node), ec); 129 108 } 130 109
Note: See TracChangeset
for help on using the changeset viewer.