Changeset 102208 in webkit


Ignore:
Timestamp:
Dec 6, 2011 7:17:05 PM (12 years ago)
Author:
rniwa@webkit.org
Message:

The code to create a NodeListsNodeData is duplicated everywhere
https://bugs.webkit.org/show_bug.cgi?id=73961

Reviewed by Darin Adler.

Extracted the logic to create NodeListsNodeData as NodeRareData::ensureNodeLists.

  • dom/Document.cpp:

(WebCore::Document::getItems):

  • dom/Node.cpp:

(WebCore::Node::childNodes):
(WebCore::Node::registerDynamicNodeList):
(WebCore::Node::getElementsByTagName):
(WebCore::Node::getElementsByTagNameNS):
(WebCore::Node::getElementsByName):
(WebCore::Node::getElementsByClassName):

  • dom/NodeRareData.h:

(WebCore::NodeRareData::ensureNodeLists):

  • html/HTMLFormControlElement.cpp:

(WebCore::HTMLFormControlElement::labels):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r102207 r102208  
     12011-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
    1242011-12-06  Leo Yang  <leo.yang@torchmobile.com.cn>
    225
  • trunk/Source/WebCore/dom/Document.cpp

    r102080 r102208  
    51575157PassRefPtr<NodeList> Document::getItems(const String& typeNames)
    51585158{
    5159     NodeRareData* data = ensureRareData();
    5160     if (!data->nodeLists()) {
    5161         data->setNodeLists(NodeListsNodeData::create());
    5162         treeScope()->addNodeListCache();
    5163     }
     5159    NodeListsNodeData* nodeLists = ensureRareData()->ensureNodeLists();
    51645160
    51655161    // Since documet.getItem() is allowed for microdata, typeNames will be null string.
     
    51675163    String localTypeNames = typeNames.isNull() ? String("http://webkit.org/microdata/undefinedItemType") : typeNames;
    51685164
    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);
    51705166    if (!result.second)
    51715167        return PassRefPtr<NodeList>(result.first->second);
  • trunk/Source/WebCore/dom/Node.cpp

    r102119 r102208  
    624624PassRefPtr<NodeList> Node::childNodes()
    625625{
    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());
    636630}
    637631
     
    10061000{
    10071001    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()))
    10131004        data->nodeLists()->invalidateCaches();
    1014     }
    10151005
    10161006    if (list->hasOwnCaches())
    1017         data->nodeLists()->m_listsWithCaches.add(list);
     1007        data->ensureNodeLists(this)->m_listsWithCaches.add(list);
    10181008}
    10191009
     
    16681658        return 0;
    16691659
    1670     NodeRareData* data = ensureRareData();
    1671     if (!data->nodeLists()) {
    1672         data->setNodeLists(NodeListsNodeData::create());
    1673         treeScope()->addNodeListCache();
    1674     }
    1675 
    16761660    String name = localName;
    16771661    if (document()->isHTMLDocument())
     
    16801664    AtomicString localNameAtom = name;
    16811665
    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);
    16831667    if (!result.second)
    16841668        return PassRefPtr<TagNodeList>(result.first->second);
     
    16971681        return getElementsByTagName(localName);
    16981682
    1699     NodeRareData* data = ensureRareData();
    1700     if (!data->nodeLists()) {
    1701         data->setNodeLists(NodeListsNodeData::create());
    1702         treeScope()->addNodeListCache();
    1703     }
    1704 
    17051683    String name = localName;
    17061684    if (document()->isHTMLDocument())
     
    17091687    AtomicString localNameAtom = name;
    17101688
    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);
    17121691    if (!result.second)
    17131692        return PassRefPtr<TagNodeList>(result.first->second);
     
    17201699PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
    17211700{
    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);
    17291702    if (!result.second)
    17301703        return PassRefPtr<NodeList>(result.first->second);
     
    17371710PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
    17381711{
    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);
    17461714    if (!result.second)
    17471715        return PassRefPtr<NodeList>(result.first->second);
     
    30413009#endif
    30423010
     3011void NodeRareData::createNodeLists(Node* node)
     3012{
     3013    ASSERT(node);
     3014    setNodeLists(NodeListsNodeData::create());
     3015    if (TreeScope* treeScope = node->treeScope())
     3016        treeScope->addNodeListCache();
     3017}
     3018
    30433019} // namespace WebCore
    30443020
  • trunk/Source/WebCore/dom/NodeRareData.h

    r101144 r102208  
    127127    void setNodeLists(PassOwnPtr<NodeListsNodeData> lists) { m_nodeLists = lists; }
    128128    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    }
    129135
    130136    short tabIndex() const { return m_tabIndex; }
     
    226232
    227233private:
     234    void createNodeLists(Node*);
     235
    228236    TreeScope* m_treeScope;
    229237    OwnPtr<NodeListsNodeData> m_nodeLists;
  • trunk/Source/WebCore/html/HTMLFormControlElement.cpp

    r96484 r102208  
    493493        return 0;
    494494
    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;
    503498
    504499    RefPtr<LabelsNodeList> list = LabelsNodeList::create(this);
    505     data->nodeLists()->m_labelsNodeListCache = list.get();
     500    nodeLists->m_labelsNodeListCache = list.get();
    506501    return list.release();
    507502}
Note: See TracChangeset for help on using the changeset viewer.