From 0a91ced941c146189dcb4c3e8cbc3c1d81bea43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 9 Jul 2017 12:36:33 +0200 Subject: [PATCH] refactoring, use continue in loop instead of nesting --- lib/astutils.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index cc60a92f4..442e46fa5 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -421,31 +421,33 @@ bool isVariableChangedByFunctionCall(const Token *tok, const Settings *settings, bool isVariableChanged(const Token *start, const Token *end, const unsigned int varid, const Settings *settings) { for (const Token *tok = start; tok != end; tok = tok->next()) { - if (tok->varId() == varid) { - if (Token::Match(tok, "%name% %assign%|++|--")) - return true; + if (tok->varId() != varid) { + continue; + } - if (Token::Match(tok->previous(), "++|-- %name%")) - return true; + if (Token::Match(tok, "%name% %assign%|++|--")) + return true; - const Token *ftok = tok; - while (ftok && !Token::Match(ftok, "[({[]")) - ftok = ftok->astParent(); + if (Token::Match(tok->previous(), "++|-- %name%")) + return true; - if (ftok && Token::Match(ftok->link(), ") !!{")) { - bool inconclusive = false; - bool isChanged = isVariableChangedByFunctionCall(tok, settings, &inconclusive); - isChanged |= inconclusive; - if (isChanged) - return true; - } + const Token *ftok = tok; + while (ftok && !Token::Match(ftok, "[({[]")) + ftok = ftok->astParent(); - const Token *parent = tok->astParent(); - while (Token::Match(parent, ".|::")) - parent = parent->astParent(); - if (parent && parent->tokType() == Token::eIncDecOp) + if (ftok && Token::Match(ftok->link(), ") !!{")) { + bool inconclusive = false; + bool isChanged = isVariableChangedByFunctionCall(tok, settings, &inconclusive); + isChanged |= inconclusive; + if (isChanged) return true; } + + const Token *parent = tok->astParent(); + while (Token::Match(parent, ".|::")) + parent = parent->astParent(); + if (parent && parent->tokType() == Token::eIncDecOp) + return true; } return false; }