From 3518db0bbecd2b10fac714e006f52d66a4f7a992 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 28 Feb 2012 00:11:28 +0100 Subject: [PATCH] QDomNode: don't needlessly call virtual functions Commit 4dabe78387d10495f9f6d0a7395f2ba3c80432bd changed these functions from virtuals to inlines that check the return value of the remaining virtual function nodeType(). However, two of the functions call nodeType() more than once, which we know will return the same result each time, but requires a compiler with interprocedural optimization capabilities to figure out by itself. So instead of repeatedly calling nodeType(), call it once and store its return value in a temporary, and use the temp for further comparisions. Change-Id: Idbeafb7fd93d275d475218c6df2ad7fdc9162cc5 Reviewed-by: Richard J. Moore --- src/xml/dom/qdom.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/xml/dom/qdom.cpp b/src/xml/dom/qdom.cpp index c16fd03613..0171fc7bef 100644 --- a/src/xml/dom/qdom.cpp +++ b/src/xml/dom/qdom.cpp @@ -172,14 +172,16 @@ public: bool isDocumentType() const { return nodeType() == QDomNode::DocumentTypeNode; } bool isElement() const { return nodeType() == QDomNode::ElementNode; } bool isEntityReference() const { return nodeType() == QDomNode::EntityReferenceNode; } - bool isText() const { return (nodeType() == QDomNode::TextNode) - || (nodeType() == QDomNode::CDATASectionNode); } + bool isText() const { const QDomNode::NodeType nt = nodeType(); + return (nt == QDomNode::TextNode) + || (nt == QDomNode::CDATASectionNode); } bool isEntity() const { return nodeType() == QDomNode::EntityNode; } bool isNotation() const { return nodeType() == QDomNode::NotationNode; } bool isProcessingInstruction() const { return nodeType() == QDomNode::ProcessingInstructionNode; } - bool isCharacterData() const { return (nodeType() == QDomNode::CharacterDataNode) - || (nodeType() == QDomNode::TextNode) - || (nodeType() == QDomNode::CommentNode); } + bool isCharacterData() const { const QDomNode::NodeType nt = nodeType(); + return (nt == QDomNode::CharacterDataNode) + || (nt == QDomNode::TextNode) + || (nt == QDomNode::CommentNode); } bool isComment() const { return nodeType() == QDomNode::CommentNode; } virtual QDomNode::NodeType nodeType() const { return QDomNode::BaseNode; }