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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/xml/XPathStep.cpp
diff --git a/Source/core/xml/XPathStep.cpp b/Source/core/xml/XPathStep.cpp
index bf490bab10b51c75580ffcfcabfaf721046bf013..c6fdc805b483a292fc3466fcb900133f1af6dda6 100644
--- a/Source/core/xml/XPathStep.cpp
+++ b/Source/core/xml/XPathStep.cpp
@@ -166,8 +166,10 @@ static inline Node::NodeType primaryNodeType(Step::Axis axis)
static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step::NodeTest& nodeTest)
{
switch (nodeTest.kind()) {
- case Step::NodeTest::TextNodeTest:
- return node->nodeType() == Node::TEXT_NODE || node->nodeType() == Node::CDATA_SECTION_NODE;
+ case Step::NodeTest::TextNodeTest: {
+ Node::NodeType type = node->nodeType();
+ return type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE;
+ }
case Step::NodeTest::CommentNodeTest:
return node->nodeType() == Node::COMMENT_NODE;
case Step::NodeTest::ProcessingInstructionNodeTest: {
@@ -198,21 +200,22 @@ static inline bool nodeMatchesBasicTest(Node* node, Step::Axis axis, const Step:
// For other axes, the principal node type is element.
ASSERT(primaryNodeType(axis) == Node::ELEMENT_NODE);
- if (node->nodeType() != Node::ELEMENT_NODE)
+ if (!node->isElementNode())
return false;
+ Element& element = toElement(*node);
if (name == starAtom)
- return namespaceURI.isEmpty() || namespaceURI == node->namespaceURI();
+ return namespaceURI.isEmpty() || namespaceURI == element.namespaceURI();
- if (node->document().isHTMLDocument()) {
- if (node->isHTMLElement()) {
+ if (element.document().isHTMLDocument()) {
+ if (element.isHTMLElement()) {
// Paths without namespaces should match HTML elements in HTML documents despite those having an XHTML namespace. Names are compared case-insensitively.
- return equalIgnoringCase(toElement(node)->localName(), name) && (namespaceURI.isNull() || namespaceURI == node->namespaceURI());
+ return equalIgnoringCase(element.localName(), name) && (namespaceURI.isNull() || namespaceURI == element.namespaceURI());
}
// An expression without any prefix shouldn't match no-namespace nodes (because HTML5 says so).
- return toElement(node)->hasLocalName(name) && namespaceURI == node->namespaceURI() && !namespaceURI.isNull();
+ return element.hasLocalName(name) && namespaceURI == element.namespaceURI() && !namespaceURI.isNull();
}
- return toElement(node)->hasLocalName(name) && namespaceURI == node->namespaceURI();
+ return element.hasLocalName(name) && namespaceURI == element.namespaceURI();
}
}
ASSERT_NOT_REACHED();

Powered by Google App Engine
This is Rietveld 408576698