From 72b00b35f8b2db2dd439c8bf2bc942eed064585e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Kr=C3=BCger?= Date: Mon, 10 Aug 2015 01:38:48 +0200 Subject: [PATCH] Tokenizer::simplifyNamespaceStd() check condition only once instead of potentially 3 times --- lib/tokenize.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 89a9ab7d6..557537990 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9588,21 +9588,21 @@ void Tokenizer::simplifyNamespaceStd() for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) { bool insert = false; - if (Token::Match(tok, "%name% (") && !Token::Match(tok->previous(), ".|::") && !Token::Match(tok->linkAt(1)->next(), "%name%|{") && stdFunctions.find(tok->str()) != stdFunctions.end()) - insert = true; - else if (Token::Match(tok, "%name% <") && !Token::Match(tok->previous(), ".|::") && stdTemplates.find(tok->str()) != stdTemplates.end()) - insert = true; - else if (tok->isName() && !tok->varId() && !Token::Match(tok->next(), "(|<") && !Token::Match(tok->previous(), ".|::") && stdTypes.find(tok->str()) != stdTypes.end()) - insert = true; + if (!Token::Match(tok->previous(), ".|::")) { + if (Token::Match(tok, "%name% (") && !Token::Match(tok->linkAt(1)->next(), "%name%|{") && stdFunctions.find(tok->str()) != stdFunctions.end()) + insert = true; + else if (Token::Match(tok, "%name% <") && stdTemplates.find(tok->str()) != stdTemplates.end()) + insert = true; + else if (tok->isName() && !tok->varId() && !Token::Match(tok->next(), "(|<") && stdTypes.find(tok->str()) != stdTypes.end()) + insert = true; + } if (insert) { tok->previous()->insertToken("std"); tok->previous()->linenr(tok->linenr()); // For stylistic reasons we put the std:: in the same line as the following token tok->previous()->fileIndex(tok->fileIndex()); tok->previous()->insertToken("::"); - } - - else if (isCPP11 && Token::Match(tok, "!!:: tr1 ::")) + } else if (isCPP11 && Token::Match(tok, "!!:: tr1 ::")) tok->next()->str("std"); }