| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> | 2 * Copyright (C) 2005 Frerich Raabe <raabe@kde.org> |
| 3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2009 Apple Inc. All rights reserved. |
| 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } else { | 79 } else { |
| 80 remainingPredicates.append(predicate); | 80 remainingPredicates.append(predicate); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 swap(remainingPredicates, m_predicates); | 83 swap(remainingPredicates, m_predicates); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool optimizeStepPair(Step* first, Step* second) | 86 bool optimizeStepPair(Step* first, Step* second) |
| 87 { | 87 { |
| 88 if (first->m_axis == Step::DescendantOrSelfAxis | 88 if (first->m_axis == Step::DescendantOrSelfAxis |
| 89 && first->nodeTest().kind() == Step::NodeTest::AnyNodeTest | 89 && first->nodeTest().getKind() == Step::NodeTest::AnyNodeTest |
| 90 && !first->m_predicates.size() | 90 && !first->m_predicates.size() |
| 91 && !first->nodeTest().mergedPredicates().size()) { | 91 && !first->nodeTest().mergedPredicates().size()) { |
| 92 | 92 |
| 93 ASSERT(first->nodeTest().data().isEmpty()); | 93 ASSERT(first->nodeTest().data().isEmpty()); |
| 94 ASSERT(first->nodeTest().namespaceURI().isEmpty()); | 94 ASSERT(first->nodeTest().namespaceURI().isEmpty()); |
| 95 | 95 |
| 96 // Optimize the common case of "//" AKA | 96 // Optimize the common case of "//" AKA |
| 97 // /descendant-or-self::node()/child::NodeTest to /descendant::NodeTest. | 97 // /descendant-or-self::node()/child::NodeTest to /descendant::NodeTest. |
| 98 if (second->m_axis == Step::ChildAxis && second->predicatesAreContextLis
tInsensitive()) { | 98 if (second->m_axis == Step::ChildAxis && second->predicatesAreContextLis
tInsensitive()) { |
| 99 first->m_axis = Step::DescendantAxis; | 99 first->m_axis = Step::DescendantAxis; |
| 100 first->nodeTest() = Step::NodeTest(second->nodeTest().kind(), second
->nodeTest().data(), second->nodeTest().namespaceURI()); | 100 first->nodeTest() = Step::NodeTest(second->nodeTest().getKind(), sec
ond->nodeTest().data(), second->nodeTest().namespaceURI()); |
| 101 swap(second->nodeTest().mergedPredicates(), first->nodeTest().merged
Predicates()); | 101 swap(second->nodeTest().mergedPredicates(), first->nodeTest().merged
Predicates()); |
| 102 swap(second->m_predicates, first->m_predicates); | 102 swap(second->m_predicates, first->m_predicates); |
| 103 first->optimize(); | 103 first->optimize(); |
| 104 return true; | 104 return true; |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool Step::predicatesAreContextListInsensitive() const | 110 bool Step::predicatesAreContextListInsensitive() const |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 return Node::ATTRIBUTE_NODE; | 160 return Node::ATTRIBUTE_NODE; |
| 161 default: | 161 default: |
| 162 return Node::ELEMENT_NODE; | 162 return Node::ELEMENT_NODE; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 #endif | 165 #endif |
| 166 | 166 |
| 167 // Evaluate NodeTest without considering merged predicates. | 167 // Evaluate NodeTest without considering merged predicates. |
| 168 static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step:
:NodeTest& nodeTest) | 168 static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step:
:NodeTest& nodeTest) |
| 169 { | 169 { |
| 170 switch (nodeTest.kind()) { | 170 switch (nodeTest.getKind()) { |
| 171 case Step::NodeTest::TextNodeTest: { | 171 case Step::NodeTest::TextNodeTest: { |
| 172 Node::NodeType type = node->getNodeType(); | 172 Node::NodeType type = node->getNodeType(); |
| 173 return type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE; | 173 return type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE; |
| 174 } | 174 } |
| 175 case Step::NodeTest::CommentNodeTest: | 175 case Step::NodeTest::CommentNodeTest: |
| 176 return node->getNodeType() == Node::COMMENT_NODE; | 176 return node->getNodeType() == Node::COMMENT_NODE; |
| 177 case Step::NodeTest::ProcessingInstructionNodeTest: { | 177 case Step::NodeTest::ProcessingInstructionNodeTest: { |
| 178 const AtomicString& name = nodeTest.data(); | 178 const AtomicString& name = nodeTest.data(); |
| 179 return node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE && (name
.isEmpty() || node->nodeName() == name); | 179 return node->getNodeType() == Node::PROCESSING_INSTRUCTION_NODE && (name
.isEmpty() || node->nodeName() == name); |
| 180 } | 180 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 return; | 363 return; |
| 364 } | 364 } |
| 365 | 365 |
| 366 case AttributeAxis: { | 366 case AttributeAxis: { |
| 367 if (!context->isElementNode()) | 367 if (!context->isElementNode()) |
| 368 return; | 368 return; |
| 369 | 369 |
| 370 Element* contextElement = toElement(context); | 370 Element* contextElement = toElement(context); |
| 371 // Avoid lazily creating attribute nodes for attributes that we do not | 371 // Avoid lazily creating attribute nodes for attributes that we do not |
| 372 // need anyway. | 372 // need anyway. |
| 373 if (nodeTest().kind() == NodeTest::NameTest && nodeTest().data() != star
Atom) { | 373 if (nodeTest().getKind() == NodeTest::NameTest && nodeTest().data() != s
tarAtom) { |
| 374 RefPtrWillBeRawPtr<Attr> attr = contextElement->getAttributeNodeNS(n
odeTest().namespaceURI(), nodeTest().data()); | 374 RefPtrWillBeRawPtr<Attr> attr = contextElement->getAttributeNodeNS(n
odeTest().namespaceURI(), nodeTest().data()); |
| 375 // In XPath land, namespace nodes are not accessible on the attribut
e axis. | 375 // In XPath land, namespace nodes are not accessible on the attribut
e axis. |
| 376 if (attr && attr->namespaceURI() != XMLNSNames::xmlnsNamespaceURI) { | 376 if (attr && attr->namespaceURI() != XMLNSNames::xmlnsNamespaceURI) { |
| 377 // Still need to check merged predicates. | 377 // Still need to check merged predicates. |
| 378 if (nodeMatches(evaluationContext, attr.get(), AttributeAxis, no
deTest())) | 378 if (nodeMatches(evaluationContext, attr.get(), AttributeAxis, no
deTest())) |
| 379 nodes.append(attr.release()); | 379 nodes.append(attr.release()); |
| 380 } | 380 } |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 | 383 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 nodes.markSorted(false); | 428 nodes.markSorted(false); |
| 429 return; | 429 return; |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 ASSERT_NOT_REACHED(); | 432 ASSERT_NOT_REACHED(); |
| 433 } | 433 } |
| 434 | 434 |
| 435 } // namespace XPath | 435 } // namespace XPath |
| 436 | 436 |
| 437 } // namespace blink | 437 } // namespace blink |
| OLD | NEW |