2011-05-23 Roland Steiner <rolandsteiner@chromium.org>
authorrolandsteiner@chromium.org <rolandsteiner@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 May 2011 17:47:46 +0000 (17:47 +0000)
committerrolandsteiner@chromium.org <rolandsteiner@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 May 2011 17:47:46 +0000 (17:47 +0000)
        Reviewed by Dimitri Glazkov.

        Update node list cache count on the containing TreeScope rather than the Document
        https://bugs.webkit.org/show_bug.cgi?id=59983

        Change code to call add/removeNodeListCache() and hasNodeListCaches() on the proper tree scope.
        Move updating of the node list cache count from setDocument() to setTreeScopeRecursively().
        Make setDocument() and setDocumentRecursively() private.

        No new tests. (refactoring)

        * dom/ContainerNode.cpp:
        (WebCore::ContainerNode::childrenChanged):
        * dom/Node.cpp:
        (WebCore::Node::~Node):
        (WebCore::Node::setDocument):
        (WebCore::Node::setTreeScopeRecursively):
        (WebCore::Node::childNodes):
        (WebCore::Node::registerDynamicNodeList):
        (WebCore::Node::unregisterDynamicNodeList):
        (WebCore::Node::notifyLocalNodeListsAttributeChanged):
        (WebCore::Node::notifyLocalNodeListsChildrenChanged):
        (WebCore::Node::getElementsByTagName):
        (WebCore::Node::getElementsByTagNameNS):
        (WebCore::Node::getElementsByName):
        (WebCore::Node::getElementsByClassName):
        * dom/Node.h:
        * html/HTMLFormControlElement.cpp:
        (WebCore::HTMLFormControlElement::labels):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87079 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/ContainerNode.cpp
Source/WebCore/dom/Node.cpp
Source/WebCore/dom/Node.h
Source/WebCore/html/HTMLFormControlElement.cpp

index 4058781..7dd726c 100644 (file)
@@ -1,3 +1,35 @@
+2011-05-23  Roland Steiner  <rolandsteiner@chromium.org>
+
+        Reviewed by Dimitri Glazkov.
+
+        Update node list cache count on the containing TreeScope rather than the Document
+        https://bugs.webkit.org/show_bug.cgi?id=59983
+
+        Change code to call add/removeNodeListCache() and hasNodeListCaches() on the proper tree scope.
+        Move updating of the node list cache count from setDocument() to setTreeScopeRecursively().
+        Make setDocument() and setDocumentRecursively() private.
+
+        No new tests. (refactoring)
+
+        * dom/ContainerNode.cpp:
+        (WebCore::ContainerNode::childrenChanged):
+        * dom/Node.cpp:
+        (WebCore::Node::~Node):
+        (WebCore::Node::setDocument):
+        (WebCore::Node::setTreeScopeRecursively):
+        (WebCore::Node::childNodes):
+        (WebCore::Node::registerDynamicNodeList):
+        (WebCore::Node::unregisterDynamicNodeList):
+        (WebCore::Node::notifyLocalNodeListsAttributeChanged):
+        (WebCore::Node::notifyLocalNodeListsChildrenChanged):
+        (WebCore::Node::getElementsByTagName):
+        (WebCore::Node::getElementsByTagNameNS):
+        (WebCore::Node::getElementsByName):
+        (WebCore::Node::getElementsByClassName):
+        * dom/Node.h:
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::labels):
+
 2011-05-23  Yury Semikhatsky  <yurys@chromium.org>
 
         Reviewed by Pavel Feldman.
index 32b0936..3ff3111 100644 (file)
@@ -812,7 +812,7 @@ void ContainerNode::childrenChanged(bool changedByParser, Node* beforeChange, No
     Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
     if (!changedByParser && childCountDelta)
         document()->nodeChildrenChanged(this);
-    if (document()->hasNodeListCaches())
+    if (treeScope()->hasNodeListCaches())
         notifyNodeListsChildrenChanged();
 }
 
index 64e4300..52fb35d 100644 (file)
@@ -390,8 +390,8 @@ Node::~Node()
     if (!hasRareData())
         ASSERT(!NodeRareData::rareDataMap().contains(this));
     else {
-        if (m_document && rareData()->nodeLists())
-            m_document->removeNodeListCache();
+        if (treeScope() && rareData()->nodeLists())
+            treeScope()->removeNodeListCache();
         
         NodeRareData::NodeRareDataMap& dataMap = NodeRareData::rareDataMap();
         NodeRareData::NodeRareDataMap::iterator it = dataMap.find(this);
@@ -454,12 +454,6 @@ void Node::setDocument(Document* document)
     willMoveToNewOwnerDocument();
     ASSERT(willMoveToNewOwnerDocumentWasCalled);
 
-    if (hasRareData() && rareData()->nodeLists()) {
-        if (m_document)
-            m_document->removeNodeListCache();
-        document->addNodeListCache();
-    }
-
     if (m_document) {
         m_document->moveNodeIteratorsToNewDocument(this, document);
         m_document->guardDeref();
@@ -510,6 +504,12 @@ void Node::setTreeScopeRecursively(TreeScope* newTreeScope, bool includeRoot)
         } else
             node->ensureRareData()->setTreeScope(newTreeScope);
 
+        if (node->hasRareData() && node->rareData()->nodeLists()) {
+            if (currentTreeScope)
+                currentTreeScope->removeNodeListCache();
+            newTreeScope->addNodeListCache();
+        }
+
         node->setDocument(newDocument);
 
         if (!node->isElementNode())
@@ -606,8 +606,8 @@ PassRefPtr<NodeList> Node::childNodes()
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        if (document())
-            document()->addNodeListCache();
+        if (treeScope())
+            treeScope()->addNodeListCache();
     }
 
     return ChildNodeList::create(this, data->nodeLists()->m_childNodeListCaches.get());
@@ -978,8 +978,8 @@ void Node::registerDynamicNodeList(DynamicNodeList* list)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
-    } else if (!m_document || !m_document->hasNodeListCaches()) {
+        treeScope()->addNodeListCache();
+    } else if (!treeScope() || !treeScope()->hasNodeListCaches()) {
         // We haven't been receiving notifications while there were no registered lists, so the cache is invalid now.
         data->nodeLists()->invalidateCaches();
     }
@@ -997,8 +997,8 @@ void Node::unregisterDynamicNodeList(DynamicNodeList* list)
         data->nodeLists()->m_listsWithCaches.remove(list);
         if (data->nodeLists()->isEmpty()) {
             data->clearNodeLists();
-            if (document())
-                document()->removeNodeListCache();
+            if (treeScope())
+                treeScope()->removeNodeListCache();
         }
     }
 }
@@ -1018,7 +1018,7 @@ void Node::notifyLocalNodeListsAttributeChanged()
 
     if (data->nodeLists()->isEmpty()) {
         data->clearNodeLists();
-        document()->removeNodeListCache();
+        treeScope()->removeNodeListCache();
     }
 }
 
@@ -1044,7 +1044,7 @@ void Node::notifyLocalNodeListsChildrenChanged()
 
     if (data->nodeLists()->isEmpty()) {
         data->clearNodeLists();
-        document()->removeNodeListCache();
+        treeScope()->removeNodeListCache();
     }
 }
 
@@ -1822,7 +1822,7 @@ PassRefPtr<NodeList> Node::getElementsByTagName(const AtomicString& localName)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
+        treeScope()->addNodeListCache();
     }
 
     String name = localName;
@@ -1851,7 +1851,7 @@ PassRefPtr<NodeList> Node::getElementsByTagNameNS(const AtomicString& namespaceU
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
+        treeScope()->addNodeListCache();
     }
 
     String name = localName;
@@ -1874,7 +1874,7 @@ PassRefPtr<NodeList> Node::getElementsByName(const String& elementName)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
+        treeScope()->addNodeListCache();
     }
 
     pair<NodeListsNodeData::NameNodeListCache::iterator, bool> result = data->nodeLists()->m_nameNodeListCache.add(elementName, 0);
@@ -1891,7 +1891,7 @@ PassRefPtr<NodeList> Node::getElementsByClassName(const String& classNames)
     NodeRareData* data = ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
+        treeScope()->addNodeListCache();
     }
 
     pair<NodeListsNodeData::ClassNodeListCache::iterator, bool> result = data->nodeLists()->m_classNodeListCache.add(classNames, 0);
index e5f31b5..5958fa9 100644 (file)
@@ -636,11 +636,6 @@ protected:
     };
     Node(Document*, ConstructionType);
 
-    // Do not use this method to change the document of a node until after the node has been
-    // removed from its previous document.
-    void setDocument(Document*);
-    void setDocumentRecursively(Document*);
-
     virtual void willMoveToNewOwnerDocument();
     virtual void didMoveToNewOwnerDocument();
     
@@ -654,6 +649,11 @@ protected:
     NodeRareData* ensureRareData();
 
 private:
+    // Do not use this method to change the document of a node until after the node has been
+    // removed from its previous document.
+    void setDocumentRecursively(Document*);
+    void setDocument(Document*);
+
     enum EditableLevel { Editable, RichlyEditable };
     bool rendererIsEditable(EditableLevel) const;
 
index ae02ebe..735aecd 100644 (file)
@@ -487,7 +487,7 @@ PassRefPtr<NodeList> HTMLFormControlElement::labels()
     NodeRareData* data = Node::ensureRareData();
     if (!data->nodeLists()) {
         data->setNodeLists(NodeListsNodeData::create());
-        document()->addNodeListCache();
+        treeScope()->addNodeListCache();
     }
 
     if (data->nodeLists()->m_labelsNodeListCache)