Optimising: about 5% improvement with Visual Studio executable
This commit is contained in:
parent
6edf35ebf5
commit
94ebb24d3d
|
@ -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()
|
||||
{
|
||||
// Skip this check for .c files
|
||||
|
@ -2551,6 +2533,14 @@ void CheckOther::checkMisusedScopedObject()
|
|||
|
||||
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)
|
||||
{
|
||||
SymbolDatabase::SpaceInfo *info = *i;
|
||||
|
@ -2576,7 +2566,7 @@ void CheckOther::checkMisusedScopedObject()
|
|||
|
||||
if (Token::Match(tok, "[;{}] %var% (")
|
||||
&& Token::Match(tok->tokAt(2)->link(), ") ;")
|
||||
&& isIdentifierObjectType(tok)
|
||||
&& identifiers.find(tok->next()->str()) != identifiers.end()
|
||||
)
|
||||
{
|
||||
tok = tok->next();
|
||||
|
|
|
@ -293,16 +293,6 @@ private:
|
|||
|
||||
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;
|
||||
};
|
||||
/// @}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue