From 45996b1404cf552bf1c41dbc718c71e12b8b184f Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Thu, 24 Aug 2017 18:23:44 +0300 Subject: [PATCH] Simplify code, read attribute once --- lib/checkunusedfunctions.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 93d211522..949b4c34b 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -353,18 +353,22 @@ void CheckUnusedFunctions::analyseWholeProgram(ErrorLogger * const errorLogger, continue; for (const tinyxml2::XMLElement *e = rootNode->FirstChildElement(); e; e = e->NextSiblingElement()) { - if (std::strcmp(e->Name(), "FileInfo") == 0) { - const char *checkattr = e->Attribute("check"); - if (checkattr && std::strcmp(checkattr,"CheckUnusedFunctions")==0) { - for (const tinyxml2::XMLElement *e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { - if (!e2->Attribute("functionName")) - continue; - if (std::strcmp(e2->Name(),"functiondecl")==0 && e2->Attribute("lineNumber")) { - decls[e2->Attribute("functionName")] = Location(sourcefile, std::atoi(e2->Attribute("lineNumber"))); - } else if (std::strcmp(e2->Name(),"functioncall")==0) { - calls.insert(e2->Attribute("functionName")); - } - } + if (std::strcmp(e->Name(), "FileInfo") != 0) + continue; + const char *checkattr = e->Attribute("check"); + if (checkattr == nullptr || std::strcmp(checkattr,"CheckUnusedFunctions") != 0) + continue; + for (const tinyxml2::XMLElement *e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { + const char* functionName = e2->Attribute("functionName"); + if (functionName == nullptr) + continue; + if (std::strcmp(e2->Name(),"functioncall") == 0) { + calls.insert(functionName); + continue; + } else if (std::strcmp(e2->Name(),"functiondecl") == 0) { + const char* lineNumber = e2->Attribute("lineNumber"); + if (lineNumber) + decls[functionName] = Location(sourcefile, std::atoi(lineNumber)); } } }