Improve speed with files containing classes.
E.g. measured speed difference was 1m11.042s --> 0m45.005s with one large test file.
This commit is contained in:
parent
a0a4008e17
commit
e93179dd9a
|
@ -864,6 +864,20 @@ void Tokenizer::setVarId()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Member functions in this source
|
||||||
|
std::list<Token *> allMemberFunctions;
|
||||||
|
{
|
||||||
|
const std::string funcpattern("%var% :: %var% (");
|
||||||
|
for (Token *tok2 = _tokens; tok2; tok2 = tok2->next())
|
||||||
|
{
|
||||||
|
// Found a class function..
|
||||||
|
if (Token::Match(tok2, funcpattern.c_str()))
|
||||||
|
{
|
||||||
|
allMemberFunctions.push_back(tok2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// class members..
|
// class members..
|
||||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
|
@ -873,7 +887,7 @@ void Tokenizer::setVarId()
|
||||||
|
|
||||||
|
|
||||||
// What member variables are there in this class?
|
// What member variables are there in this class?
|
||||||
std::list<const Token *> varlist;
|
std::map<std::string, unsigned int> varlist;
|
||||||
{
|
{
|
||||||
unsigned int indentlevel = 0;
|
unsigned int indentlevel = 0;
|
||||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||||
|
@ -890,7 +904,7 @@ void Tokenizer::setVarId()
|
||||||
|
|
||||||
// Found a member variable..
|
// Found a member variable..
|
||||||
else if (indentlevel == 1 && tok2->varId() > 0)
|
else if (indentlevel == 1 && tok2->varId() > 0)
|
||||||
varlist.push_back(tok2);
|
varlist[tok2->str()] = tok2->varId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,8 +917,10 @@ void Tokenizer::setVarId()
|
||||||
std::list<Token *> funclist;
|
std::list<Token *> funclist;
|
||||||
{
|
{
|
||||||
const std::string funcpattern(classname + " :: %var% (");
|
const std::string funcpattern(classname + " :: %var% (");
|
||||||
for (Token *tok2 = tok; tok2; tok2 = tok2->next())
|
for (std::list<Token *>::iterator func = allMemberFunctions.begin(); func != allMemberFunctions.end(); ++func)
|
||||||
{
|
{
|
||||||
|
Token *tok2 = *func;
|
||||||
|
|
||||||
// Found a class function..
|
// Found a class function..
|
||||||
if (Token::Match(tok2, funcpattern.c_str()))
|
if (Token::Match(tok2, funcpattern.c_str()))
|
||||||
{
|
{
|
||||||
|
@ -925,32 +941,30 @@ void Tokenizer::setVarId()
|
||||||
if (funclist.empty())
|
if (funclist.empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
// Update the variable ids..
|
// Update the variable ids..
|
||||||
for (std::list<const Token *>::const_iterator var = varlist.begin(); var != varlist.end(); ++var)
|
// Parse each function..
|
||||||
|
for (std::list<Token *>::iterator func = funclist.begin(); func != funclist.end(); ++func)
|
||||||
{
|
{
|
||||||
const unsigned int varid((*var)->varId());
|
unsigned int indentlevel = 0;
|
||||||
const std::string &varname((*var)->str());
|
for (Token *tok2 = *func; tok2; tok2 = tok2->next())
|
||||||
|
|
||||||
// Parse each function..
|
|
||||||
for (std::list<Token *>::iterator func = funclist.begin(); func != funclist.end(); ++func)
|
|
||||||
{
|
{
|
||||||
unsigned int indentlevel = 0;
|
if (tok2->str() == "{")
|
||||||
for (Token *tok2 = *func; tok2; tok2 = tok2->next())
|
++indentlevel;
|
||||||
|
else if (tok2->str() == "}")
|
||||||
{
|
{
|
||||||
if (tok2->str() == "{")
|
if (indentlevel <= 1)
|
||||||
++indentlevel;
|
break;
|
||||||
else if (tok2->str() == "}")
|
--indentlevel;
|
||||||
{
|
}
|
||||||
if (indentlevel <= 1)
|
else if (indentlevel > 0 &&
|
||||||
break;
|
tok2->varId() == 0 &&
|
||||||
--indentlevel;
|
varlist.find(tok2->str()) != varlist.end())
|
||||||
}
|
{
|
||||||
else if (indentlevel > 0 && tok2->str() == varname && tok2->varId() == 0)
|
tok2->varId(varlist[tok2->str()]);
|
||||||
tok2->varId(varid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue