⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 275872 in webkit


Ignore:
Timestamp:
Apr 13, 2021, 2:05:44 AM (6 years ago)
Author:
rniwa@webkit.org
Message:

Use WTF::compactMap in HTMLSlotElement
​https://bugs.webkit.org/show_bug.cgi?id=224470

Reviewed by Antti Koivisto.

Cleaned up the code in assignedNodes and assignedElements with WTF::compactMap.

  • html/HTMLSlotElement.cpp:

(WebCore::HTMLSlotElement::assignedNodes const):
(WebCore::HTMLSlotElement::assignedElements const):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r275871 r275872  
     12021-04-13  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Use WTF::compactMap in HTMLSlotElement
     4        https://bugs.webkit.org/show_bug.cgi?id=224470
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Cleaned up the code in assignedNodes and assignedElements with WTF::compactMap.
     9
     10        * html/HTMLSlotElement.cpp:
     11        (WebCore::HTMLSlotElement::assignedNodes const):
     12        (WebCore::HTMLSlotElement::assignedElements const):
     13
    1142021-04-13  Philippe Normand  <pnormand@igalia.com>
    215
  • trunk/Source/WebCore/html/HTMLSlotElement.cpp

    r266212 r275872  
    142142        return nodes;
    143143    }
    144     auto* assignedNodes = this->assignedNodes();
    145     if (!assignedNodes)
    146         return { };
    147144
    148     Vector<Ref<Node>> nodes;
    149     nodes.reserveInitialCapacity(assignedNodes->size());
    150     for (auto& nodePtr : *assignedNodes) {
    151         auto* node = nodePtr.get();
    152         if (UNLIKELY(!node))
    153             continue;
    154         nodes.uncheckedAppend(*node);
     145    if (auto* nodes = assignedNodes(); nodes) {
     146        return WTF::compactMap(*nodes, [](auto& nodeWeakPtr) -> RefPtr<Node> {
     147            return nodeWeakPtr.get();
     148        });
    155149    }
    156150
    157     return nodes;
     151    return { };
    158152}
    159153
    160154Vector<Ref<Element>> HTMLSlotElement::assignedElements(const AssignedNodesOptions& options) const
    161155{
    162     auto nodes = assignedNodes(options);
    163 
    164     Vector<Ref<Element>> elements;
    165     elements.reserveCapacity(nodes.size());
    166     for (auto& node : nodes) {
    167         if (is<Element>(node))
    168             elements.uncheckedAppend(static_reference_cast<Element>(WTFMove(node)));
    169     }
    170 
    171     return elements;
     156    return WTF::compactMap(assignedNodes(options), [](auto&& node) -> RefPtr<Element> {
     157        if (!is<Element>(node))
     158            return nullptr;
     159        return static_reference_cast<Element>(WTFMove(node));
     160    });
    172161}
    173162
Note: See TracChangeset for help on using the changeset viewer.