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

Side by Side Diff: Source/core/xml/XPathStep.cpp

Issue 308963002: Minimize calls to Node::nodeType() as it is virtual (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix typo Created 6 years, 6 months 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 | Annotate | Revision Log
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. 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 default: 159 default:
160 return Node::ELEMENT_NODE; 160 return Node::ELEMENT_NODE;
161 } 161 }
162 } 162 }
163 #endif 163 #endif
164 164
165 // Evaluate NodeTest without considering merged predicates. 165 // Evaluate NodeTest without considering merged predicates.
166 static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step: :NodeTest& nodeTest) 166 static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step: :NodeTest& nodeTest)
167 { 167 {
168 switch (nodeTest.kind()) { 168 switch (nodeTest.kind()) {
169 case Step::NodeTest::TextNodeTest: 169 case Step::NodeTest::TextNodeTest: {
170 return node->nodeType() == Node::TEXT_NODE || node->nodeType() == No de::CDATA_SECTION_NODE; 170 Node::NodeType type = node->nodeType();
171 return type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE;
172 }
171 case Step::NodeTest::CommentNodeTest: 173 case Step::NodeTest::CommentNodeTest:
172 return node->nodeType() == Node::COMMENT_NODE; 174 return node->nodeType() == Node::COMMENT_NODE;
173 case Step::NodeTest::ProcessingInstructionNodeTest: { 175 case Step::NodeTest::ProcessingInstructionNodeTest: {
174 const AtomicString& name = nodeTest.data(); 176 const AtomicString& name = nodeTest.data();
175 return node->nodeType() == Node::PROCESSING_INSTRUCTION_NODE && (nam e.isEmpty() || node->nodeName() == name); 177 return node->nodeType() == Node::PROCESSING_INSTRUCTION_NODE && (nam e.isEmpty() || node->nodeName() == name);
176 } 178 }
177 case Step::NodeTest::AnyNodeTest: 179 case Step::NodeTest::AnyNodeTest:
178 return true; 180 return true;
179 case Step::NodeTest::NameTest: { 181 case Step::NodeTest::NameTest: {
180 const AtomicString& name = nodeTest.data(); 182 const AtomicString& name = nodeTest.data();
(...skipping 10 matching lines...) Expand all
191 return namespaceURI.isEmpty() || node->namespaceURI() == nam espaceURI; 193 return namespaceURI.isEmpty() || node->namespaceURI() == nam espaceURI;
192 194
193 return node->localName() == name && node->namespaceURI() == name spaceURI; 195 return node->localName() == name && node->namespaceURI() == name spaceURI;
194 } 196 }
195 197
196 // Node test on the namespace axis is not implemented yet, the calle r has a check for it. 198 // Node test on the namespace axis is not implemented yet, the calle r has a check for it.
197 ASSERT(axis != Step::NamespaceAxis); 199 ASSERT(axis != Step::NamespaceAxis);
198 200
199 // For other axes, the principal node type is element. 201 // For other axes, the principal node type is element.
200 ASSERT(primaryNodeType(axis) == Node::ELEMENT_NODE); 202 ASSERT(primaryNodeType(axis) == Node::ELEMENT_NODE);
201 if (node->nodeType() != Node::ELEMENT_NODE) 203 if (!node->isElementNode())
202 return false; 204 return false;
205 Element& element = toElement(*node);
203 206
204 if (name == starAtom) 207 if (name == starAtom)
205 return namespaceURI.isEmpty() || namespaceURI == node->namespace URI(); 208 return namespaceURI.isEmpty() || namespaceURI == element.namespa ceURI();
206 209
207 if (node->document().isHTMLDocument()) { 210 if (element.document().isHTMLDocument()) {
208 if (node->isHTMLElement()) { 211 if (element.isHTMLElement()) {
209 // Paths without namespaces should match HTML elements in HT ML documents despite those having an XHTML namespace. Names are compared case-in sensitively. 212 // Paths without namespaces should match HTML elements in HT ML documents despite those having an XHTML namespace. Names are compared case-in sensitively.
210 return equalIgnoringCase(toElement(node)->localName(), name) && (namespaceURI.isNull() || namespaceURI == node->namespaceURI()); 213 return equalIgnoringCase(element.localName(), name) && (name spaceURI.isNull() || namespaceURI == element.namespaceURI());
211 } 214 }
212 // An expression without any prefix shouldn't match no-namespace nodes (because HTML5 says so). 215 // An expression without any prefix shouldn't match no-namespace nodes (because HTML5 says so).
213 return toElement(node)->hasLocalName(name) && namespaceURI == no de->namespaceURI() && !namespaceURI.isNull(); 216 return element.hasLocalName(name) && namespaceURI == element.nam espaceURI() && !namespaceURI.isNull();
214 } 217 }
215 return toElement(node)->hasLocalName(name) && namespaceURI == node-> namespaceURI(); 218 return element.hasLocalName(name) && namespaceURI == element.namespa ceURI();
216 } 219 }
217 } 220 }
218 ASSERT_NOT_REACHED(); 221 ASSERT_NOT_REACHED();
219 return false; 222 return false;
220 } 223 }
221 224
222 static inline bool nodeMatches(Node* node, Step::Axis axis, const Step::NodeTest & nodeTest) 225 static inline bool nodeMatches(Node* node, Step::Axis axis, const Step::NodeTest & nodeTest)
223 { 226 {
224 if (!nodeMatchesBasicTest(node, axis, nodeTest)) 227 if (!nodeMatchesBasicTest(node, axis, nodeTest))
225 return false; 228 return false;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 nodes.markSorted(false); 402 nodes.markSorted(false);
400 return; 403 return;
401 } 404 }
402 } 405 }
403 ASSERT_NOT_REACHED(); 406 ASSERT_NOT_REACHED();
404 } 407 }
405 408
406 409
407 } 410 }
408 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698