Optimising: about 5% improvement with Visual Studio executable

This commit is contained in:
Daniel Marjamäki 2011-01-15 20:55:51 +01:00
parent 6edf35ebf5
commit 94ebb24d3d
2 changed files with 9 additions and 29 deletions

View File

@ -2519,24 +2519,6 @@ void CheckOther::checkMathFunctions()
} }
} }
bool CheckOther::isIdentifierObjectType(const Token * const tok)
{
const std::string identifier = tok->tokAt(1)->str();
const std::map<std::string, bool>::const_iterator found = isClassResults.find(identifier);
if (found != isClassResults.end())
{
return found->second;
}
const std::string classDefnOrDecl = std::string("class|struct ") + identifier + " [{:;]";
const bool result = Token::findmatch(_tokenizer->tokens(), classDefnOrDecl.c_str()) != NULL;
isClassResults.insert(std::make_pair(identifier, result));
return result;
}
void CheckOther::checkMisusedScopedObject() void CheckOther::checkMisusedScopedObject()
{ {
// Skip this check for .c files // Skip this check for .c files
@ -2551,6 +2533,14 @@ void CheckOther::checkMisusedScopedObject()
std::list<SymbolDatabase::SpaceInfo *>::iterator i; std::list<SymbolDatabase::SpaceInfo *>::iterator i;
// list of classes / structs
std::set<std::string> identifiers;
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (Token::Match(tok, "class|struct %var% [:{]"))
identifiers.insert(tok->next()->str());
}
for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i) for (i = symbolDatabase->spaceInfoList.begin(); i != symbolDatabase->spaceInfoList.end(); ++i)
{ {
SymbolDatabase::SpaceInfo *info = *i; SymbolDatabase::SpaceInfo *info = *i;
@ -2576,7 +2566,7 @@ void CheckOther::checkMisusedScopedObject()
if (Token::Match(tok, "[;{}] %var% (") if (Token::Match(tok, "[;{}] %var% (")
&& Token::Match(tok->tokAt(2)->link(), ") ;") && Token::Match(tok->tokAt(2)->link(), ") ;")
&& isIdentifierObjectType(tok) && identifiers.find(tok->next()->str()) != identifiers.end()
) )
{ {
tok = tok->next(); tok = tok->next();

View File

@ -293,16 +293,6 @@ private:
return varname; return varname;
} }
/**
* @brief query type of identifier
* @param tok Token of the identifier
* @return true if the identifier is of type 'class' or 'struct',
* false otherwise.
*/
bool isIdentifierObjectType(const Token* const tok);
std::map<std::string, bool> isClassResults;
}; };
/// @} /// @}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------