Merge pull request #515 from Dmitry-Me/simplifyTernaryOps

Simplify ternary operators, use else-if to avoid extra comparison
This commit is contained in:
PKEuS 2015-02-09 12:11:40 +01:00
commit 38c8c3734d
1 changed files with 6 additions and 5 deletions

View File

@ -237,8 +237,11 @@ static bool bailoutSelfAssignment(const Token * const tok)
static bool isReturn(const Token *tok) static bool isReturn(const Token *tok)
{ {
const Token *prev = tok ? tok->previous() : nullptr; if (!tok)
if (Token::simpleMatch(prev ? prev->previous() : nullptr, "} ;")) return false;
const Token *prev = tok->previous();
if (prev && Token::simpleMatch(prev->previous(), "} ;"))
prev = prev->previous(); prev = prev->previous();
if (Token::simpleMatch(prev, "}")) { if (Token::simpleMatch(prev, "}")) {
@ -249,9 +252,7 @@ static bool isReturn(const Token *tok)
!Token::findsimplematch(prev->link(), "break", prev)) { !Token::findsimplematch(prev->link(), "break", prev)) {
return true; return true;
} }
} } else if (Token::simpleMatch(prev, ";")) {
if (Token::simpleMatch(prev, ";")) {
// noreturn function // noreturn function
if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% (")) if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% ("))
return true; return true;