Changeset 102208 in webkit
- Timestamp:
- Dec 6, 2011 7:17:05 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r102207 r102208 1 2011-12-06 Ryosuke Niwa <rniwa@webkit.org> 2 3 The code to create a NodeListsNodeData is duplicated everywhere 4 https://bugs.webkit.org/show_bug.cgi?id=73961 5 6 Reviewed by Darin Adler. 7 8 Extracted the logic to create NodeListsNodeData as NodeRareData::ensureNodeLists. 9 10 * dom/Document.cpp: 11 (WebCore::Document::getItems): 12 * dom/Node.cpp: 13 (WebCore::Node::childNodes): 14 (WebCore::Node::registerDynamicNodeList): 15 (WebCore::Node::getElementsByTagName): 16 (WebCore::Node::getElementsByTagNameNS): 17 (WebCore::Node::getElementsByName): 18 (WebCore::Node::getElementsByClassName): 19 * dom/NodeRareData.h: 20 (WebCore::NodeRareData::ensureNodeLists): 21 * html/HTMLFormControlElement.cpp: 22 (WebCore::HTMLFormControlElement::labels): 23 1 24 2011-12-06 Leo Yang <leo.yang@torchmobile.com.cn> 2 25 -
trunk/Source/WebCore/dom/Document.cpp
r102080 r102208 5157 5157 PassRefPtr<NodeList> Document::getItems(const String& typeNames) 5158 5158 { 5159 NodeRareData* data = ensureRareData(); 5160 if (!data->nodeLists()) { 5161 data->setNodeLists(NodeListsNodeData::create()); 5162 treeScope()->addNodeListCache(); 5163 } 5159 NodeListsNodeData* nodeLists = ensureRareData()->ensureNodeLists(); 5164 5160 5165 5161 // Since documet.getItem() is allowed for microdata, typeNames will be null string. … … 5167 5163 String localTypeNames = typeNames.isNull() ? String("http://webkit.org/microdata/undefinedItemType") : typeNames; 5168 5164 5169 pair<NodeListsNodeData::MicroDataItemListCache::iterator, bool> result = data->nodeLists()->m_microDataItemListCache.add(localTypeNames, 0);5165 pair<NodeListsNodeData::MicroDataItemListCache::iterator, bool> result = nodeLists->m_microDataItemListCache.add(localTypeNames, 0); 5170 5166 if (!result.second) 5171 5167 return PassRefPtr<NodeList>(result.first->second); -
trunk/Source/WebCore/dom/Node.cpp
r102119 r102208 624 624 PassRefPtr<NodeList> Node::childNodes() 625 625 { 626 NodeRareData* data = ensureRareData(); 627 if (!data->nodeLists()) { 628 data->setNodeLists(NodeListsNodeData::create()); 629 if (treeScope()) 630 treeScope()->addNodeListCache(); 631 } 632 633 if (!data->nodeLists()->m_childNodeListCaches) 634 data->nodeLists()->m_childNodeListCaches = DynamicNodeList::Caches::create(); 635 return ChildNodeList::create(this, data->nodeLists()->m_childNodeListCaches.get()); 626 NodeListsNodeData* nodeLists = ensureRareData()->ensureNodeLists(this); 627 if (!nodeLists->m_childNodeListCaches) 628 nodeLists->m_childNodeListCaches = DynamicNodeList::Caches::create(); 629 return ChildNodeList::create(this, nodeLists->m_childNodeListCaches.get()); 636 630 } 637 631 … … 1006 1000 { 1007 1001 NodeRareData* data = ensureRareData(); 1008 if (!data->nodeLists()) { 1009 data->setNodeLists(NodeListsNodeData::create()); 1010 treeScope()->addNodeListCache(); 1011 } else if (!treeScope() || !treeScope()->hasNodeListCaches()) { 1012 // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now. 1002 // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now. 1003 if (data->nodeLists() && (!treeScope() || !treeScope()->hasNodeListCaches())) 1013 1004 data->nodeLists()->invalidateCaches(); 1014 }1015 1005 1016 1006 if (list->hasOwnCaches()) 1017 data-> nodeLists()->m_listsWithCaches.add(list);1007 data->ensureNodeLists(this)->m_listsWithCaches.add(list); 1018 1008 } 1019 1009 … … 1668 1658 return 0; 1669 1659 1670 NodeRareData* data = ensureRareData();1671 if (!data->nodeLists()) {1672 data->setNodeLists(NodeListsNodeData::create());1673 treeScope()->addNodeListCache();1674 }1675 1676 1660 String name = localName; 1677 1661 if (document()->isHTMLDocument()) … … 1680 1664 AtomicString localNameAtom = name; 1681 1665 1682 pair<NodeListsNodeData::TagNodeListCache::iterator, bool> result = data->nodeLists()->m_tagNodeListCache.add(localNameAtom, 0);1666 pair<NodeListsNodeData::TagNodeListCache::iterator, bool> result = ensureRareData()->ensureNodeLists(this)->m_tagNodeListCache.add(localNameAtom, 0); 1683 1667 if (!result.second) 1684 1668 return PassRefPtr<TagNodeList>(result.first->second); … … 1697 1681 return getElementsByTagName(localName); 1698 1682 1699 NodeRareData* data = ensureRareData();1700 if (!data->nodeLists()) {1701 data->setNodeLists(NodeListsNodeData::create());1702 treeScope()->addNodeListCache();1703 }1704 1705 1683 String name = localName; 1706 1684 if (document()->isHTMLDocument()) … … 1709 1687 AtomicString localNameAtom = name; 1710 1688 1711 pair<NodeListsNodeData::TagNodeListCacheNS::iterator, bool> result = data->nodeLists()->m_tagNodeListCacheNS.add(QualifiedName(nullAtom, localNameAtom, namespaceURI).impl(), 0); 1689 pair<NodeListsNodeData::TagNodeListCacheNS::iterator, bool> result 1690 = ensureRareData()->ensureNodeLists(this)->m_tagNodeListCacheNS.add(QualifiedName(nullAtom, localNameAtom, namespaceURI).impl(), 0); 1712 1691 if (!result.second) 1713 1692 return PassRefPtr<TagNodeList>(result.first->second); … … 1720 1699 PassRefPtr<NodeList> Node::getElementsByName(const String& elementName) 1721 1700 { 1722 NodeRareData* data = ensureRareData(); 1723 if (!data->nodeLists()) { 1724 data->setNodeLists(NodeListsNodeData::create()); 1725 treeScope()->addNodeListCache(); 1726 } 1727 1728 pair<NodeListsNodeData::NameNodeListCache::iterator, bool> result = data->nodeLists()->m_nameNodeListCache.add(elementName, 0); 1701 pair<NodeListsNodeData::NameNodeListCache::iterator, bool> result = ensureRareData()->ensureNodeLists(this)->m_nameNodeListCache.add(elementName, 0); 1729 1702 if (!result.second) 1730 1703 return PassRefPtr<NodeList>(result.first->second); … … 1737 1710 PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames) 1738 1711 { 1739 NodeRareData* data = ensureRareData(); 1740 if (!data->nodeLists()) { 1741 data->setNodeLists(NodeListsNodeData::create()); 1742 treeScope()->addNodeListCache(); 1743 } 1744 1745 pair<NodeListsNodeData::ClassNodeListCache::iterator, bool> result = data->nodeLists()->m_classNodeListCache.add(classNames, 0); 1712 pair<NodeListsNodeData::ClassNodeListCache::iterator, bool> result 1713 = ensureRareData()->ensureNodeLists(this)->m_classNodeListCache.add(classNames, 0); 1746 1714 if (!result.second) 1747 1715 return PassRefPtr<NodeList>(result.first->second); … … 3041 3009 #endif 3042 3010 3011 void NodeRareData::createNodeLists(Node* node) 3012 { 3013 ASSERT(node); 3014 setNodeLists(NodeListsNodeData::create()); 3015 if (TreeScope* treeScope = node->treeScope()) 3016 treeScope->addNodeListCache(); 3017 } 3018 3043 3019 } // namespace WebCore 3044 3020 -
trunk/Source/WebCore/dom/NodeRareData.h
r101144 r102208 127 127 void setNodeLists(PassOwnPtr<NodeListsNodeData> lists) { m_nodeLists = lists; } 128 128 NodeListsNodeData* nodeLists() const { return m_nodeLists.get(); } 129 NodeListsNodeData* ensureNodeLists(Node* node) 130 { 131 if (!m_nodeLists) 132 createNodeLists(node); 133 return m_nodeLists.get(); 134 } 129 135 130 136 short tabIndex() const { return m_tabIndex; } … … 226 232 227 233 private: 234 void createNodeLists(Node*); 235 228 236 TreeScope* m_treeScope; 229 237 OwnPtr<NodeListsNodeData> m_nodeLists; -
trunk/Source/WebCore/html/HTMLFormControlElement.cpp
r96484 r102208 493 493 return 0; 494 494 495 NodeRareData* data = Node::ensureRareData(); 496 if (!data->nodeLists()) { 497 data->setNodeLists(NodeListsNodeData::create()); 498 treeScope()->addNodeListCache(); 499 } 500 501 if (data->nodeLists()->m_labelsNodeListCache) 502 return data->nodeLists()->m_labelsNodeListCache; 495 NodeListsNodeData* nodeLists = Node::ensureRareData()->ensureNodeLists(this); 496 if (nodeLists->m_labelsNodeListCache) 497 return nodeLists->m_labelsNodeListCache; 503 498 504 499 RefPtr<LabelsNodeList> list = LabelsNodeList::create(this); 505 data->nodeLists()->m_labelsNodeListCache = list.get();500 nodeLists->m_labelsNodeListCache = list.get(); 506 501 return list.release(); 507 502 }
Note: See TracChangeset
for help on using the changeset viewer.