Modernize StaticNodeList / StaticElementList
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2016 21:34:16 +0000 (21:34 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2016 21:34:16 +0000 (21:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159831

Reviewed by Ryosuke Niwa.

Modernize StaticNodeList / StaticElementList. Pass vector to adopt
as an rvalue reference instead of a non-const reference.

* bindings/js/JSHTMLAllCollectionCustom.cpp:
(WebCore::namedItems):
* dom/ChildListMutationScope.cpp:
(WebCore::ChildListMutationAccumulator::enqueueMutationRecord):
* dom/MutationRecord.cpp:
* dom/SelectorQuery.cpp:
(WebCore::SelectorDataList::queryAll):
* dom/StaticNodeList.h:
* dom/WebKitNamedFlow.cpp:
(WebCore::WebKitNamedFlow::getRegionsByContent):
(WebCore::WebKitNamedFlow::getRegions):
(WebCore::WebKitNamedFlow::getContent):
* svg/SVGSVGElement.cpp:
(WebCore::SVGSVGElement::collectIntersectionOrEnclosureList):
* testing/Internals.cpp:
(WebCore::Internals::nodesFromRect):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSHTMLAllCollectionCustom.cpp
Source/WebCore/dom/ChildListMutationScope.cpp
Source/WebCore/dom/MutationRecord.cpp
Source/WebCore/dom/SelectorQuery.cpp
Source/WebCore/dom/StaticNodeList.h
Source/WebCore/dom/WebKitNamedFlow.cpp
Source/WebCore/svg/SVGSVGElement.cpp
Source/WebCore/testing/Internals.cpp

index 7491fb7..59318a0 100644 (file)
@@ -1,3 +1,30 @@
+2016-07-15  Chris Dumez  <cdumez@apple.com>
+
+        Modernize StaticNodeList / StaticElementList
+        https://bugs.webkit.org/show_bug.cgi?id=159831
+
+        Reviewed by Ryosuke Niwa.
+
+        Modernize StaticNodeList / StaticElementList. Pass vector to adopt
+        as an rvalue reference instead of a non-const reference.
+
+        * bindings/js/JSHTMLAllCollectionCustom.cpp:
+        (WebCore::namedItems):
+        * dom/ChildListMutationScope.cpp:
+        (WebCore::ChildListMutationAccumulator::enqueueMutationRecord):
+        * dom/MutationRecord.cpp:
+        * dom/SelectorQuery.cpp:
+        (WebCore::SelectorDataList::queryAll):
+        * dom/StaticNodeList.h:
+        * dom/WebKitNamedFlow.cpp:
+        (WebCore::WebKitNamedFlow::getRegionsByContent):
+        (WebCore::WebKitNamedFlow::getRegions):
+        (WebCore::WebKitNamedFlow::getContent):
+        * svg/SVGSVGElement.cpp:
+        (WebCore::SVGSVGElement::collectIntersectionOrEnclosureList):
+        * testing/Internals.cpp:
+        (WebCore::Internals::nodesFromRect):
+
 2016-07-15  Brent Fulgham  <bfulgham@apple.com>
 
         Block insecure script running in a data: frame when the top-level page is HTTPS
index 3966c95..a2aa15c 100644 (file)
@@ -47,7 +47,7 @@ static JSValue namedItems(ExecState& state, JSHTMLAllCollection* collection, Pro
 
     // FIXME: HTML5 specification says this should be a HTMLCollection.
     // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#htmlallcollection
-    return toJS(&state, collection->globalObject(), StaticElementList::adopt(namedItems));
+    return toJS(&state, collection->globalObject(), StaticElementList::create(WTFMove(namedItems)));
 }
 
 // HTMLAllCollections are strange objects, they support both get and call.
index eadcdd0..d02d852 100644 (file)
@@ -127,7 +127,7 @@ void ChildListMutationAccumulator::enqueueMutationRecord()
     ASSERT(hasObservers());
     ASSERT(!isEmpty());
 
-    auto record = MutationRecord::createChildList(m_target, StaticNodeList::adopt(m_addedNodes), StaticNodeList::adopt(m_removedNodes), WTFMove(m_previousSibling), WTFMove(m_nextSibling));
+    auto record = MutationRecord::createChildList(m_target, StaticNodeList::create(WTFMove(m_addedNodes)), StaticNodeList::create(WTFMove(m_removedNodes)), WTFMove(m_previousSibling), WTFMove(m_nextSibling));
     m_observers->enqueueMutationRecord(WTFMove(record));
     m_lastAdded = nullptr;
     ASSERT(isEmpty());
index 402686e..22955e5 100644 (file)
@@ -83,7 +83,7 @@ private:
     static NodeList* lazilyInitializeEmptyNodeList(RefPtr<NodeList>& nodeList)
     {
         if (!nodeList)
-            nodeList = StaticNodeList::createEmpty();
+            nodeList = StaticNodeList::create();
         return nodeList.get();
     }
 
index f7f294e..56517f5 100644 (file)
@@ -165,7 +165,7 @@ RefPtr<NodeList> SelectorDataList::queryAll(ContainerNode& rootNode) const
 {
     Vector<Ref<Element>> result;
     execute<AllElementExtractorSelectorQueryTrait>(rootNode, result);
-    return StaticElementList::adopt(result);
+    return StaticElementList::create(WTFMove(result));
 }
 
 struct SingleElementExtractorSelectorQueryTrait {
index e523c9b..3f886de 100644 (file)
@@ -39,48 +39,36 @@ namespace WebCore {
 
 class WEBCORE_EXPORT StaticNodeList final : public NodeList {
 public:
-    static Ref<StaticNodeList> adopt(Vector<Ref<Node>>& nodes)
+    static Ref<StaticNodeList> create(Vector<Ref<Node>>&& nodes = { })
     {
-        Ref<StaticNodeList> nodeList = adoptRef(*new StaticNodeList);
-        nodeList->m_nodes.swap(nodes);
-        return nodeList;
-    }
-
-    static Ref<StaticNodeList> createEmpty()
-    {
-        return adoptRef(*new StaticNodeList);
+        return adoptRef(*new StaticNodeList(WTFMove(nodes)));
     }
 
     unsigned length() const override;
     Node* item(unsigned index) const override;
 
 private:
-    StaticNodeList() { }
+    StaticNodeList(Vector<Ref<Node>>&& nodes)
+        : m_nodes(WTFMove(nodes))
+    { }
 
     Vector<Ref<Node>> m_nodes;
 };
 
 class StaticElementList final : public NodeList {
 public:
-    static Ref<StaticElementList> adopt(Vector<Ref<Element>>& elements)
-    {
-        Ref<StaticElementList> nodeList = adoptRef(*new StaticElementList);
-        nodeList->m_elements.swap(elements);
-        return nodeList;
-    }
-
-    static Ref<StaticElementList> createEmpty()
+    static Ref<StaticElementList> create(Vector<Ref<Element>>&& elements = { })
     {
-        return adoptRef(*new StaticElementList);
+        return adoptRef(*new StaticElementList(WTFMove(elements)));
     }
 
     unsigned length() const override;
     Element* item(unsigned index) const override;
 
 private:
-    StaticElementList()
-    {
-    }
+    StaticElementList(Vector<Ref<Element>>&& elements)
+        : m_elements(WTFMove(elements))
+    }
 
     Vector<Ref<Element>> m_elements;
 };
index 2d2b4e3..dc94f11 100644 (file)
@@ -122,7 +122,7 @@ int WebKitNamedFlow::firstEmptyRegionIndex() const
 Ref<NodeList> WebKitNamedFlow::getRegionsByContent(Node* contentNode)
 {
     if (!contentNode)
-        return StaticElementList::createEmpty();
+        return StaticElementList::create();
 
     if (m_flowManager->document())
         m_flowManager->document()->updateLayoutIgnorePendingStylesheets();
@@ -130,7 +130,7 @@ Ref<NodeList> WebKitNamedFlow::getRegionsByContent(Node* contentNode)
     // The renderer may be destroyed or created after the style update.
     // Because this is called from JS, where the wrapper keeps a reference to the NamedFlow, no guard is necessary.
     if (!m_parentFlowThread)
-        return StaticElementList::createEmpty();
+        return StaticElementList::create();
 
     Vector<Ref<Element>> regionElements;
 
@@ -150,7 +150,7 @@ Ref<NodeList> WebKitNamedFlow::getRegionsByContent(Node* contentNode)
         }
     }
 
-    return StaticElementList::adopt(regionElements);
+    return StaticElementList::create(WTFMove(regionElements));
 }
 
 Ref<NodeList> WebKitNamedFlow::getRegions()
@@ -161,7 +161,7 @@ Ref<NodeList> WebKitNamedFlow::getRegions()
     // The renderer may be destroyed or created after the style update.
     // Because this is called from JS, where the wrapper keeps a reference to the NamedFlow, no guard is necessary.
     if (!m_parentFlowThread)
-        return StaticElementList::createEmpty();
+        return StaticElementList::create();
 
     Vector<Ref<Element>> regionElements;
 
@@ -177,7 +177,7 @@ Ref<NodeList> WebKitNamedFlow::getRegions()
         regionElements.append(*namedFlowFragment.generatingElement());
     }
 
-    return StaticElementList::adopt(regionElements);
+    return StaticElementList::create(WTFMove(regionElements));
 }
 
 Ref<NodeList> WebKitNamedFlow::getContent()
@@ -188,17 +188,17 @@ Ref<NodeList> WebKitNamedFlow::getContent()
     // The renderer may be destroyed or created after the style update.
     // Because this is called from JS, where the wrapper keeps a reference to the NamedFlow, no guard is necessary.
     if (!m_parentFlowThread)
-        return StaticElementList::createEmpty();
+        return StaticElementList::create();
 
+    auto& contentElementsList = m_parentFlowThread->contentElements();
     Vector<Ref<Element>> contentElements;
-
-    const NamedFlowContentElements& contentElementsList = m_parentFlowThread->contentElements();
+    contentElements.reserveInitialCapacity(contentElementsList.size());
     for (auto& element : contentElementsList) {
         ASSERT(element->computedStyle()->flowThread() == m_parentFlowThread->flowThreadName());
-        contentElements.append(*element);
+        contentElements.uncheckedAppend(*element);
     }
 
-    return StaticElementList::adopt(contentElements);
+    return StaticElementList::create(WTFMove(contentElements));
 }
 
 void WebKitNamedFlow::setRenderer(RenderNamedFlowThread* parentFlowThread)
index 788c1fc..283b2da 100644 (file)
@@ -316,7 +316,7 @@ Ref<NodeList> SVGSVGElement::collectIntersectionOrEnclosureList(const FloatRect&
         if (checkFunction(&element, rect))
             elements.append(element);
     }
-    return RefPtr<NodeList>(StaticElementList::adopt(elements)).releaseNonNull();
+    return StaticElementList::create(WTFMove(elements));
 }
 
 Ref<NodeList> SVGSVGElement::getIntersectionList(const FloatRect& rect, SVGElement* referenceElement)
index 2c4688b..eeb9617 100644 (file)
@@ -1455,7 +1455,7 @@ RefPtr<NodeList> Internals::nodesFromRect(Document& document, int centerX, int c
             matches.uncheckedAppend(*node);
     }
 
-    return StaticNodeList::adopt(matches);
+    return StaticNodeList::create(WTFMove(matches));
 }
 
 class GetCallerCodeBlockFunctor {