Use logical instead of bitwise operators to save cpu

This commit is contained in:
Dmitry-Me 2014-08-30 11:35:25 +02:00 committed by Daniel Marjamäki
parent e9fdfc6cd0
commit eace67ee1c
1 changed files with 15 additions and 15 deletions

View File

@ -1935,8 +1935,8 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) const
if (Token::Match(_tok, "if return|break use| ;")) if (Token::Match(_tok, "if return|break use| ;"))
_tok = _tok->tokAt(2); _tok = _tok->tokAt(2);
incase |= (_tok->str() == "case"); incase = incase || (_tok->str() == "case");
incase &= (_tok->str() != "break" && _tok->str() != "return"); incase = incase && (_tok->str() != "break" && _tok->str() != "return");
} }
if (!incase && valid) { if (!incase && valid) {
@ -2121,26 +2121,26 @@ void CheckMemoryLeakInFunction::checkScope(const Token *Tok1, const std::string
} }
// detect cases that "simplifycode" don't handle well.. // detect cases that "simplifycode" don't handle well..
else if (_settings->debugwarnings) { else if (tok && _settings->debugwarnings) {
Token *first = tok; Token *first = tok;
while (first && first->str() == ";") while (first && first->str() == ";")
first = first->next(); first = first->next();
bool noerr = false; bool noerr = false;
noerr |= Token::simpleMatch(first, "alloc ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; dealloc ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; dealloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; return use ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; return use ; }");
noerr |= Token::simpleMatch(first, "alloc ; use ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; use ; }");
noerr |= Token::simpleMatch(first, "alloc ; use ; return ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; use ; return ; }");
noerr |= Token::simpleMatch(first, "alloc ; dealloc ; return ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; dealloc ; return ; }");
noerr |= Token::simpleMatch(first, "if alloc ; dealloc ; }"); noerr = noerr || Token::simpleMatch(first, "if alloc ; dealloc ; }");
noerr |= Token::simpleMatch(first, "if alloc ; return use ; }"); noerr = noerr || Token::simpleMatch(first, "if alloc ; return use ; }");
noerr |= Token::simpleMatch(first, "if alloc ; use ; }"); noerr = noerr || Token::simpleMatch(first, "if alloc ; use ; }");
noerr |= Token::simpleMatch(first, "alloc ; ifv return ; dealloc ; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; ifv return ; dealloc ; }");
noerr |= Token::simpleMatch(first, "alloc ; if return ; dealloc; }"); noerr = noerr || Token::simpleMatch(first, "alloc ; if return ; dealloc; }");
// Unhandled case.. // Unhandled case..
if (!noerr && tok) { if (!noerr) {
std::ostringstream errmsg; std::ostringstream errmsg;
errmsg << "inconclusive leak of " << varname << ": "; errmsg << "inconclusive leak of " << varname << ": ";
errmsg << tok->stringifyList(false, false, false, false, false, 0, 0); errmsg << tok->stringifyList(false, false, false, false, false, 0, 0);