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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 namespace blink { | 39 namespace blink { |
40 namespace XPath { | 40 namespace XPath { |
41 | 41 |
42 Step::Step(Axis axis, const NodeTest& nodeTest) | 42 Step::Step(Axis axis, const NodeTest& nodeTest) |
43 : m_axis(axis) | 43 : m_axis(axis) |
44 , m_nodeTest(adoptPtrWillBeNoop(new NodeTest(nodeTest))) | 44 , m_nodeTest(adoptPtrWillBeNoop(new NodeTest(nodeTest))) |
45 { | 45 { |
46 } | 46 } |
47 | 47 |
48 Step::Step(Axis axis, const NodeTest& nodeTest, WillBeHeapVector<OwnPtrWillBeMem
ber<Predicate> >& predicates) | 48 Step::Step(Axis axis, const NodeTest& nodeTest, WillBeHeapVector<OwnPtrWillBeMem
ber<Predicate>>& predicates) |
49 : m_axis(axis) | 49 : m_axis(axis) |
50 , m_nodeTest(adoptPtrWillBeNoop(new NodeTest(nodeTest))) | 50 , m_nodeTest(adoptPtrWillBeNoop(new NodeTest(nodeTest))) |
51 { | 51 { |
52 m_predicates.swap(predicates); | 52 m_predicates.swap(predicates); |
53 } | 53 } |
54 | 54 |
55 Step::~Step() | 55 Step::~Step() |
56 { | 56 { |
57 } | 57 } |
58 | 58 |
59 DEFINE_TRACE(Step) | 59 DEFINE_TRACE(Step) |
60 { | 60 { |
61 visitor->trace(m_nodeTest); | 61 visitor->trace(m_nodeTest); |
62 visitor->trace(m_predicates); | 62 visitor->trace(m_predicates); |
63 ParseNode::trace(visitor); | 63 ParseNode::trace(visitor); |
64 } | 64 } |
65 | 65 |
66 void Step::optimize() | 66 void Step::optimize() |
67 { | 67 { |
68 // Evaluate predicates as part of node test if possible to avoid building | 68 // Evaluate predicates as part of node test if possible to avoid building |
69 // unnecessary NodeSets. | 69 // unnecessary NodeSets. |
70 // E.g., there is no need to build a set of all "foo" nodes to evaluate | 70 // E.g., there is no need to build a set of all "foo" nodes to evaluate |
71 // "foo[@bar]", we can check the predicate while enumerating. | 71 // "foo[@bar]", we can check the predicate while enumerating. |
72 // This optimization can be applied to predicates that are not context node | 72 // This optimization can be applied to predicates that are not context node |
73 // list sensitive, or to first predicate that is only context position | 73 // list sensitive, or to first predicate that is only context position |
74 // sensitive, e.g. foo[position() mod 2 = 0]. | 74 // sensitive, e.g. foo[position() mod 2 = 0]. |
75 WillBeHeapVector<OwnPtrWillBeMember<Predicate> > remainingPredicates; | 75 WillBeHeapVector<OwnPtrWillBeMember<Predicate>> remainingPredicates; |
76 for (size_t i = 0; i < m_predicates.size(); ++i) { | 76 for (size_t i = 0; i < m_predicates.size(); ++i) { |
77 OwnPtrWillBeRawPtr<Predicate> predicate(m_predicates[i].release()); | 77 OwnPtrWillBeRawPtr<Predicate> predicate(m_predicates[i].release()); |
78 if ((!predicate->isContextPositionSensitive() || nodeTest().mergedPredic
ates().isEmpty()) && !predicate->isContextSizeSensitive() && remainingPredicates
.isEmpty()) { | 78 if ((!predicate->isContextPositionSensitive() || nodeTest().mergedPredic
ates().isEmpty()) && !predicate->isContextSizeSensitive() && remainingPredicates
.isEmpty()) { |
79 nodeTest().mergedPredicates().append(predicate.release()); | 79 nodeTest().mergedPredicates().append(predicate.release()); |
80 } else { | 80 } else { |
81 remainingPredicates.append(predicate.release()); | 81 remainingPredicates.append(predicate.release()); |
82 } | 82 } |
83 } | 83 } |
84 swap(remainingPredicates, m_predicates); | 84 swap(remainingPredicates, m_predicates); |
85 } | 85 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 232 } |
233 | 233 |
234 static inline bool nodeMatches(EvaluationContext& evaluationContext, Node* node,
Step::Axis axis, const Step::NodeTest& nodeTest) | 234 static inline bool nodeMatches(EvaluationContext& evaluationContext, Node* node,
Step::Axis axis, const Step::NodeTest& nodeTest) |
235 { | 235 { |
236 if (!nodeMatchesBasicTest(node, axis, nodeTest)) | 236 if (!nodeMatchesBasicTest(node, axis, nodeTest)) |
237 return false; | 237 return false; |
238 | 238 |
239 // Only the first merged predicate may depend on position. | 239 // Only the first merged predicate may depend on position. |
240 ++evaluationContext.position; | 240 ++evaluationContext.position; |
241 | 241 |
242 const WillBeHeapVector<OwnPtrWillBeMember<Predicate> >& mergedPredicates = n
odeTest.mergedPredicates(); | 242 const WillBeHeapVector<OwnPtrWillBeMember<Predicate>>& mergedPredicates = no
deTest.mergedPredicates(); |
243 for (unsigned i = 0; i < mergedPredicates.size(); i++) { | 243 for (unsigned i = 0; i < mergedPredicates.size(); i++) { |
244 Predicate* predicate = mergedPredicates[i].get(); | 244 Predicate* predicate = mergedPredicates[i].get(); |
245 | 245 |
246 evaluationContext.node = node; | 246 evaluationContext.node = node; |
247 // No need to set context size - we only get here when evaluating | 247 // No need to set context size - we only get here when evaluating |
248 // predicates that do not depend on it. | 248 // predicates that do not depend on it. |
249 if (!predicate->evaluate(evaluationContext)) | 249 if (!predicate->evaluate(evaluationContext)) |
250 return false; | 250 return false; |
251 } | 251 } |
252 | 252 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 nodes.markSorted(false); | 430 nodes.markSorted(false); |
431 return; | 431 return; |
432 } | 432 } |
433 } | 433 } |
434 ASSERT_NOT_REACHED(); | 434 ASSERT_NOT_REACHED(); |
435 } | 435 } |
436 | 436 |
437 } | 437 } |
438 | 438 |
439 } | 439 } |
OLD | NEW |