diff options
Diffstat (limited to 'Source/WebCore/xml/XPathNodeSet.cpp')
-rw-r--r-- | Source/WebCore/xml/XPathNodeSet.cpp | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/Source/WebCore/xml/XPathNodeSet.cpp b/Source/WebCore/xml/XPathNodeSet.cpp index 5fcbfaa53..d04bd62c1 100644 --- a/Source/WebCore/xml/XPathNodeSet.cpp +++ b/Source/WebCore/xml/XPathNodeSet.cpp @@ -94,8 +94,8 @@ static void sortBlock(unsigned from, unsigned to, Vector<Vector<Node*>>& parentM unsigned sortedEnd = from; // FIXME: namespace nodes are not implemented. for (unsigned i = sortedEnd; i < to; ++i) { - Node* n = parentMatrix[i][0]; - if (n->isAttributeNode() && toAttr(n)->ownerElement() == commonAncestor) + Node* node = parentMatrix[i][0]; + if (is<Attr>(*node) && downcast<Attr>(*node).ownerElement() == commonAncestor) parentMatrix[i].swap(parentMatrix[sortedEnd++]); } if (sortedEnd != from) { @@ -155,15 +155,15 @@ void NodeSet::sort() const Vector<Vector<Node*>> parentMatrix(nodeCount); for (unsigned i = 0; i < nodeCount; ++i) { Vector<Node*>& parentsVector = parentMatrix[i]; - Node* n = m_nodes[i].get(); - parentsVector.append(n); - if (n->isAttributeNode()) { - n = toAttr(n)->ownerElement(); - parentsVector.append(n); + Node* node = m_nodes[i].get(); + parentsVector.append(node); + if (is<Attr>(*node)) { + node = downcast<Attr>(*node).ownerElement(); + parentsVector.append(node); containsAttributeNodes = true; } - while ((n = n->parentNode())) - parentsVector.append(n); + while ((node = node->parentNode())) + parentsVector.append(node); } sortBlock(0, nodeCount, parentMatrix, containsAttributeNodes); @@ -173,15 +173,15 @@ void NodeSet::sort() const for (unsigned i = 0; i < nodeCount; ++i) sortedNodes.append(parentMatrix[i][0]); - m_nodes = std::move(sortedNodes); + m_nodes = WTFMove(sortedNodes); m_isSorted = true; } static Node* findRootNode(Node* node) { - if (node->isAttributeNode()) - node = toAttr(node)->ownerElement(); - if (node->inDocument()) + if (is<Attr>(*node)) + node = downcast<Attr>(*node).ownerElement(); + if (node->isConnected()) node = &node->document(); else { while (Node* parent = node->parentNode()) @@ -197,9 +197,8 @@ void NodeSet::traversalSort() const unsigned nodeCount = m_nodes.size(); ASSERT(nodeCount > 1); - for (unsigned i = 0; i < nodeCount; ++i) { - Node* node = m_nodes[i].get(); - nodes.add(node); + for (auto& node : m_nodes) { + nodes.add(node.get()); if (node->isAttributeNode()) containsAttributeNodes = true; } @@ -207,26 +206,26 @@ void NodeSet::traversalSort() const Vector<RefPtr<Node>> sortedNodes; sortedNodes.reserveInitialCapacity(nodeCount); - for (Node* n = findRootNode(m_nodes.first().get()); n; n = NodeTraversal::next(n)) { - if (nodes.contains(n)) - sortedNodes.append(n); + for (Node* node = findRootNode(m_nodes.first().get()); node; node = NodeTraversal::next(*node)) { + if (nodes.contains(node)) + sortedNodes.append(node); - if (!containsAttributeNodes || !n->isElementNode()) + if (!containsAttributeNodes || !is<Element>(*node)) continue; - Element* element = toElement(n); - if (!element->hasAttributes()) + Element& element = downcast<Element>(*node); + if (!element.hasAttributes()) continue; - for (const Attribute& attribute : element->attributesIterator()) { - RefPtr<Attr> attr = element->attrIfExists(attribute.name()); + for (const Attribute& attribute : element.attributesIterator()) { + RefPtr<Attr> attr = element.attrIfExists(attribute.name()); if (attr && nodes.contains(attr.get())) sortedNodes.append(attr); } } ASSERT(sortedNodes.size() == nodeCount); - m_nodes = std::move(sortedNodes); + m_nodes = WTFMove(sortedNodes); m_isSorted = true; } |