Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(325)

Side by Side Diff: third_party/WebKit/Source/core/xml/XPathPath.cpp

Issue 2560823003: Avoid WTF::Vector::at() and operator[] in core/xml. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. 3 * Copyright (C) 2006, 2009 Apple Inc.
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 visitor->trace(m_predicates); 51 visitor->trace(m_predicates);
52 Expression::trace(visitor); 52 Expression::trace(visitor);
53 } 53 }
54 54
55 Value Filter::evaluate(EvaluationContext& evaluationContext) const { 55 Value Filter::evaluate(EvaluationContext& evaluationContext) const {
56 Value v = m_expr->evaluate(evaluationContext); 56 Value v = m_expr->evaluate(evaluationContext);
57 57
58 NodeSet& nodes = v.modifiableNodeSet(evaluationContext); 58 NodeSet& nodes = v.modifiableNodeSet(evaluationContext);
59 nodes.sort(); 59 nodes.sort();
60 60
61 for (unsigned i = 0; i < m_predicates.size(); i++) { 61 for (const auto& predicate : m_predicates) {
62 NodeSet* newNodes = NodeSet::create(); 62 NodeSet* newNodes = NodeSet::create();
63 evaluationContext.size = nodes.size(); 63 evaluationContext.size = nodes.size();
64 evaluationContext.position = 0; 64 evaluationContext.position = 0;
65 65
66 for (unsigned j = 0; j < nodes.size(); j++) { 66 for (const auto& node : nodes) {
67 Node* node = nodes[j];
68
69 evaluationContext.node = node; 67 evaluationContext.node = node;
70 ++evaluationContext.position; 68 ++evaluationContext.position;
71 69
72 if (m_predicates[i]->evaluate(evaluationContext)) 70 if (predicate->evaluate(evaluationContext))
73 newNodes->append(node); 71 newNodes->append(node);
74 } 72 }
75 nodes.swap(*newNodes); 73 nodes.swap(*newNodes);
76 } 74 }
77 75
78 return v; 76 return v;
79 } 77 }
80 78
81 LocationPath::LocationPath() : m_absolute(false) { 79 LocationPath::LocationPath() : m_absolute(false) {
82 setIsContextNodeSensitive(true); 80 setIsContextNodeSensitive(true);
(...skipping 29 matching lines...) Expand all
112 NodeSet* nodes = NodeSet::create(); 110 NodeSet* nodes = NodeSet::create();
113 nodes->append(context); 111 nodes->append(context);
114 evaluate(clonedContext, *nodes); 112 evaluate(clonedContext, *nodes);
115 113
116 return Value(nodes, Value::adopt); 114 return Value(nodes, Value::adopt);
117 } 115 }
118 116
119 void LocationPath::evaluate(EvaluationContext& context, NodeSet& nodes) const { 117 void LocationPath::evaluate(EvaluationContext& context, NodeSet& nodes) const {
120 bool resultIsSorted = nodes.isSorted(); 118 bool resultIsSorted = nodes.isSorted();
121 119
122 for (unsigned i = 0; i < m_steps.size(); i++) { 120 for (const auto& step : m_steps) {
123 Step* step = m_steps[i];
124 NodeSet* newNodes = NodeSet::create(); 121 NodeSet* newNodes = NodeSet::create();
125 HeapHashSet<Member<Node>> newNodesSet; 122 HeapHashSet<Member<Node>> newNodesSet;
126 123
127 bool needToCheckForDuplicateNodes = 124 bool needToCheckForDuplicateNodes =
128 !nodes.subtreesAreDisjoint() || 125 !nodes.subtreesAreDisjoint() ||
129 (step->getAxis() != Step::ChildAxis && 126 (step->getAxis() != Step::ChildAxis &&
130 step->getAxis() != Step::SelfAxis && 127 step->getAxis() != Step::SelfAxis &&
131 step->getAxis() != Step::DescendantAxis && 128 step->getAxis() != Step::DescendantAxis &&
132 step->getAxis() != Step::DescendantOrSelfAxis && 129 step->getAxis() != Step::DescendantOrSelfAxis &&
133 step->getAxis() != Step::AttributeAxis); 130 step->getAxis() != Step::AttributeAxis);
134 131
135 if (needToCheckForDuplicateNodes) 132 if (needToCheckForDuplicateNodes)
136 resultIsSorted = false; 133 resultIsSorted = false;
137 134
138 // This is a simplified check that can be improved to handle more cases. 135 // This is a simplified check that can be improved to handle more cases.
139 if (nodes.subtreesAreDisjoint() && (step->getAxis() == Step::ChildAxis || 136 if (nodes.subtreesAreDisjoint() && (step->getAxis() == Step::ChildAxis ||
140 step->getAxis() == Step::SelfAxis)) 137 step->getAxis() == Step::SelfAxis))
141 newNodes->markSubtreesDisjoint(true); 138 newNodes->markSubtreesDisjoint(true);
142 139
143 for (unsigned j = 0; j < nodes.size(); j++) { 140 for (const auto& inputNode : nodes) {
144 NodeSet* matches = NodeSet::create(); 141 NodeSet* matches = NodeSet::create();
145 step->evaluate(context, nodes[j], *matches); 142 step->evaluate(context, inputNode, *matches);
146 143
147 if (!matches->isSorted()) 144 if (!matches->isSorted())
148 resultIsSorted = false; 145 resultIsSorted = false;
149 146
150 for (size_t nodeIndex = 0; nodeIndex < matches->size(); ++nodeIndex) { 147 for (const auto& node : *matches) {
151 Node* node = (*matches)[nodeIndex];
152 if (!needToCheckForDuplicateNodes || newNodesSet.add(node).isNewEntry) 148 if (!needToCheckForDuplicateNodes || newNodesSet.add(node).isNewEntry)
153 newNodes->append(node); 149 newNodes->append(node);
154 } 150 }
155 } 151 }
156 152
157 nodes.swap(*newNodes); 153 nodes.swap(*newNodes);
158 } 154 }
159 155
160 nodes.markSorted(resultIsSorted); 156 nodes.markSorted(resultIsSorted);
161 } 157 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 193
198 NodeSet& nodes = v.modifiableNodeSet(context); 194 NodeSet& nodes = v.modifiableNodeSet(context);
199 m_path->evaluate(context, nodes); 195 m_path->evaluate(context, nodes);
200 196
201 return v; 197 return v;
202 } 198 }
203 199
204 } // namespace XPath 200 } // namespace XPath
205 201
206 } // namespace blink 202 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/xml/XPathParser.cpp ('k') | third_party/WebKit/Source/core/xml/XPathPredicate.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698