summaryrefslogtreecommitdiff
path: root/Source/WebCore/xml/XPathStep.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/xml/XPathStep.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/xml/XPathStep.cpp')
-rw-r--r--Source/WebCore/xml/XPathStep.cpp75
1 files changed, 41 insertions, 34 deletions
diff --git a/Source/WebCore/xml/XPathStep.cpp b/Source/WebCore/xml/XPathStep.cpp
index 0ae340360..5b813445b 100644
--- a/Source/WebCore/xml/XPathStep.cpp
+++ b/Source/WebCore/xml/XPathStep.cpp
@@ -30,7 +30,6 @@
#include "Attr.h"
#include "Document.h"
-#include "HTMLDocument.h"
#include "HTMLElement.h"
#include "NodeTraversal.h"
#include "XMLNSNames.h"
@@ -42,14 +41,14 @@ namespace XPath {
Step::Step(Axis axis, NodeTest nodeTest)
: m_axis(axis)
- , m_nodeTest(WTFMove(nodeTest))
+ , m_nodeTest(std::move(nodeTest))
{
}
Step::Step(Axis axis, NodeTest nodeTest, Vector<std::unique_ptr<Expression>> predicates)
: m_axis(axis)
- , m_nodeTest(WTFMove(nodeTest))
- , m_predicates(WTFMove(predicates))
+ , m_nodeTest(std::move(nodeTest))
+ , m_predicates(std::move(predicates))
{
}
@@ -63,13 +62,14 @@ void Step::optimize()
// E.g., there is no need to build a set of all "foo" nodes to evaluate "foo[@bar]", we can check the predicate while enumerating.
// This optimization can be applied to predicates that are not context node list sensitive, or to first predicate that is only context position sensitive, e.g. foo[position() mod 2 = 0].
Vector<std::unique_ptr<Expression>> remainingPredicates;
- for (auto& predicate : m_predicates) {
+ for (size_t i = 0; i < m_predicates.size(); ++i) {
+ auto& predicate = m_predicates[i];
if ((!predicateIsContextPositionSensitive(*predicate) || m_nodeTest.m_mergedPredicates.isEmpty()) && !predicate->isContextSizeSensitive() && remainingPredicates.isEmpty())
- m_nodeTest.m_mergedPredicates.append(WTFMove(predicate));
+ m_nodeTest.m_mergedPredicates.append(std::move(predicate));
else
- remainingPredicates.append(WTFMove(predicate));
+ remainingPredicates.append(std::move(predicate));
}
- m_predicates = WTFMove(remainingPredicates);
+ m_predicates = std::move(remainingPredicates);
}
void optimizeStepPair(Step& first, Step& second, bool& dropSecondStep)
@@ -99,21 +99,23 @@ void optimizeStepPair(Step& first, Step& second, bool& dropSecondStep)
return;
first.m_axis = Step::DescendantAxis;
- first.m_nodeTest = WTFMove(second.m_nodeTest);
- first.m_predicates = WTFMove(second.m_predicates);
+ first.m_nodeTest = std::move(second.m_nodeTest);
+ first.m_predicates = std::move(second.m_predicates);
first.optimize();
dropSecondStep = true;
}
bool Step::predicatesAreContextListInsensitive() const
{
- for (auto& predicate : m_predicates) {
- if (predicateIsContextPositionSensitive(*predicate) || predicate->isContextSizeSensitive())
+ for (size_t i = 0; i < m_predicates.size(); ++i) {
+ auto& predicate = *m_predicates[i];
+ if (predicateIsContextPositionSensitive(predicate) || predicate.isContextSizeSensitive())
return false;
}
- for (auto& predicate : m_nodeTest.m_mergedPredicates) {
- if (predicateIsContextPositionSensitive(*predicate) || predicate->isContextSizeSensitive())
+ for (size_t i = 0; i < m_nodeTest.m_mergedPredicates.size(); ++i) {
+ auto& predicate = *m_nodeTest.m_mergedPredicates[i];
+ if (predicateIsContextPositionSensitive(predicate) || predicate.isContextSizeSensitive())
return false;
}
@@ -128,7 +130,9 @@ void Step::evaluate(Node& context, NodeSet& nodes) const
nodesInAxis(context, nodes);
// Check predicates that couldn't be merged into node test.
- for (auto& predicate : m_predicates) {
+ for (unsigned i = 0; i < m_predicates.size(); i++) {
+ auto& predicate = *m_predicates[i];
+
NodeSet newNodes;
if (!nodes.isSorted())
newNodes.markSorted(false);
@@ -139,11 +143,11 @@ void Step::evaluate(Node& context, NodeSet& nodes) const
evaluationContext.node = node;
evaluationContext.size = nodes.size();
evaluationContext.position = j + 1;
- if (evaluatePredicate(*predicate))
+ if (evaluatePredicate(predicate))
newNodes.append(node);
}
- nodes = WTFMove(newNodes);
+ nodes = std::move(newNodes);
}
}
@@ -153,6 +157,8 @@ static inline Node::NodeType primaryNodeType(Step::Axis axis)
switch (axis) {
case Step::AttributeAxis:
return Node::ATTRIBUTE_NODE;
+ case Step::NamespaceAxis:
+ return Node::XPATH_NAMESPACE_NODE;
default:
return Node::ELEMENT_NODE;
}
@@ -195,21 +201,21 @@ inline bool nodeMatchesBasicTest(Node& node, Step::Axis axis, const Step::NodeTe
// For other axes, the principal node type is element.
ASSERT(primaryNodeType(axis) == Node::ELEMENT_NODE);
- if (!is<Element>(node))
+ if (!node.isElementNode())
return false;
if (name == starAtom)
return namespaceURI.isEmpty() || namespaceURI == node.namespaceURI();
- if (is<HTMLDocument>(node.document())) {
- if (is<HTMLElement>(node)) {
+ if (node.document().isHTMLDocument()) {
+ if (node.isHTMLElement()) {
// Paths without namespaces should match HTML elements in HTML documents despite those having an XHTML namespace. Names are compared case-insensitively.
- return equalIgnoringASCIICase(downcast<HTMLElement>(node).localName(), name) && (namespaceURI.isNull() || namespaceURI == node.namespaceURI());
+ return equalIgnoringCase(toHTMLElement(node).localName(), name) && (namespaceURI.isNull() || namespaceURI == node.namespaceURI());
}
// An expression without any prefix shouldn't match no-namespace nodes (because HTML5 says so).
- return downcast<Element>(node).hasLocalName(name) && namespaceURI == node.namespaceURI() && !namespaceURI.isNull();
+ return toElement(node).hasLocalName(name) && namespaceURI == node.namespaceURI() && !namespaceURI.isNull();
}
- return downcast<Element>(node).hasLocalName(name) && namespaceURI == node.namespaceURI();
+ return toElement(node).hasLocalName(name) && namespaceURI == node.namespaceURI();
}
}
ASSERT_NOT_REACHED();
@@ -226,10 +232,11 @@ inline bool nodeMatches(Node& node, Step::Axis axis, const Step::NodeTest& nodeT
// Only the first merged predicate may depend on position.
++evaluationContext.position;
- for (auto& predicate : nodeTest.m_mergedPredicates) {
+ auto& mergedPredicates = nodeTest.m_mergedPredicates;
+ for (unsigned i = 0; i < mergedPredicates.size(); i++) {
// No need to set context size - we only get here when evaluating predicates that do not depend on it.
evaluationContext.node = &node;
- if (!evaluatePredicate(*predicate))
+ if (!evaluatePredicate(*mergedPredicates[i]))
return false;
}
@@ -252,7 +259,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
case DescendantAxis:
if (context.isAttributeNode()) // In XPath model, attribute nodes do not have children.
return;
- for (Node* node = context.firstChild(); node; node = NodeTraversal::next(*node, &context)) {
+ for (Node* node = context.firstChild(); node; node = NodeTraversal::next(node, &context)) {
if (nodeMatches(*node, DescendantAxis, m_nodeTest))
nodes.append(node);
}
@@ -283,7 +290,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
return;
}
case FollowingSiblingAxis:
- if (context.isAttributeNode())
+ if (context.nodeType() == Node::ATTRIBUTE_NODE || context.nodeType() == Node::XPATH_NAMESPACE_NODE)
return;
for (Node* node = context.nextSibling(); node; node = node->nextSibling()) {
if (nodeMatches(*node, FollowingSiblingAxis, m_nodeTest))
@@ -291,7 +298,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
}
return;
case PrecedingSiblingAxis:
- if (context.isAttributeNode())
+ if (context.nodeType() == Node::ATTRIBUTE_NODE || context.nodeType() == Node::XPATH_NAMESPACE_NODE)
return;
for (Node* node = context.previousSibling(); node; node = node->previousSibling()) {
if (nodeMatches(*node, PrecedingSiblingAxis, m_nodeTest))
@@ -302,7 +309,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
case FollowingAxis:
if (context.isAttributeNode()) {
Node* node = static_cast<Attr&>(context).ownerElement();
- while ((node = NodeTraversal::next(*node))) {
+ while ((node = NodeTraversal::next(node))) {
if (nodeMatches(*node, FollowingAxis, m_nodeTest))
nodes.append(node);
}
@@ -311,7 +318,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
for (Node* node = parent->nextSibling(); node; node = node->nextSibling()) {
if (nodeMatches(*node, FollowingAxis, m_nodeTest))
nodes.append(node);
- for (Node* child = node->firstChild(); child; child = NodeTraversal::next(*child, node)) {
+ for (Node* child = node->firstChild(); child; child = NodeTraversal::next(child, node)) {
if (nodeMatches(*child, FollowingAxis, m_nodeTest))
nodes.append(child);
}
@@ -326,7 +333,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
else
node = &context;
while (ContainerNode* parent = node->parentNode()) {
- for (node = NodeTraversal::previous(*node); node != parent; node = NodeTraversal::previous(*node)) {
+ for (node = NodeTraversal::previous(node); node != parent; node = NodeTraversal::previous(node)) {
if (nodeMatches(*node, PrecedingAxis, m_nodeTest))
nodes.append(node);
}
@@ -336,10 +343,10 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
return;
}
case AttributeAxis: {
- if (!is<Element>(context))
+ if (!context.isElementNode())
return;
- Element& contextElement = downcast<Element>(context);
+ Element& contextElement = toElement(context);
// Avoid lazily creating attribute nodes for attributes that we do not need anyway.
if (m_nodeTest.m_kind == NodeTest::NameTest && m_nodeTest.m_data != starAtom) {
@@ -373,7 +380,7 @@ void Step::nodesInAxis(Node& context, NodeSet& nodes) const
nodes.append(&context);
if (context.isAttributeNode()) // In XPath model, attribute nodes do not have children.
return;
- for (Node* node = context.firstChild(); node; node = NodeTraversal::next(*node, &context)) {
+ for (Node* node = context.firstChild(); node; node = NodeTraversal::next(node, &context)) {
if (nodeMatches(*node, DescendantOrSelfAxis, m_nodeTest))
nodes.append(node);
}