From 7287b1a251926c39b361f69ac4d7f6f0faabf2c9 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Thu, 3 Sep 2015 18:30:05 +0300 Subject: [PATCH] Avoid unneeded match checks --- lib/checkother.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 054f1cdb5..14bc92ea2 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -58,6 +58,9 @@ void CheckOther::checkCastIntToCharAndBack() const Scope * scope = symbolDatabase->functionScopes[i]; std::map vars; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { + // Quick check to see if any of the matches below have any chances + if (!tok->isName() || !Token::Match(tok, "%var%|EOF %comp%|=")) + continue; if (Token::Match(tok, "%var% = fclose|fflush|fputc|fputs|fscanf|getchar|getc|fgetc|putchar|putc|puts|scanf|sscanf|ungetc (")) { const Variable *var = tok->variable(); if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) { @@ -80,8 +83,7 @@ void CheckOther::checkCastIntToCharAndBack() if (var && var->typeEndToken()->str() == "char" && !var->typeEndToken()->isSigned()) { vars[tok->varId()] = "cin.get"; } - } - if (Token::Match(tok, "%var% %comp% EOF")) { + } else if (Token::Match(tok, "%var% %comp% EOF")) { if (vars.find(tok->varId()) != vars.end()) { checkCastIntToCharAndBackError(tok, vars[tok->varId()]); }