From 6eacb4957cde2854e5a4236ddc8ade9b36227038 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Mon, 9 Feb 2015 11:46:27 +0300 Subject: [PATCH] Simplify ternary operators, use else-if to avoid extra comparison --- lib/valueflow.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 581693837..b11b4f29a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -237,8 +237,11 @@ static bool bailoutSelfAssignment(const Token * const tok) static bool isReturn(const Token *tok) { - const Token *prev = tok ? tok->previous() : nullptr; - if (Token::simpleMatch(prev ? prev->previous() : nullptr, "} ;")) + if (!tok) + return false; + + const Token *prev = tok->previous(); + if (prev && Token::simpleMatch(prev->previous(), "} ;")) prev = prev->previous(); if (Token::simpleMatch(prev, "}")) { @@ -249,9 +252,7 @@ static bool isReturn(const Token *tok) !Token::findsimplematch(prev->link(), "break", prev)) { return true; } - } - - if (Token::simpleMatch(prev, ";")) { + } else if (Token::simpleMatch(prev, ";")) { // noreturn function if (Token::simpleMatch(prev->previous(), ") ;") && Token::Match(prev->linkAt(-1)->tokAt(-2), "[;{}] %name% (")) return true;