Improve speed a lot for files that have long number lists like = { 0,1,2,3,4, etc. }

This commit is contained in:
Reijo Tomperi 2009-08-05 23:02:40 +03:00
parent ce8c5b0236
commit eb691857fd
1 changed files with 15 additions and 17 deletions

View File

@ -1549,7 +1549,6 @@ void Tokenizer::simplifyTokenList()
} }
simplifyComma(); simplifyComma();
createLinks();
if (_settings && _settings->_debug) if (_settings && _settings->_debug)
{ {
_tokens->printOut(); _tokens->printOut();
@ -3258,26 +3257,25 @@ void Tokenizer::syntaxError(const Token *tok, char c)
bool Tokenizer::simplifyComma() bool Tokenizer::simplifyComma()
{ {
bool ret = false; bool ret = false;
bool insideLoop = false; createLinks();
size_t indentlevel = 0;
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (tok->str() == "(") if (Token::simpleMatch(tok, "for ("))
{ {
++indentlevel; tok = tok->next()->link();
if (!tok)
break;
continue;
} }
else if (tok->str() == ")")
if (Token::simpleMatch(tok, "= {"))
{ {
--indentlevel; tok = tok->next()->link();
if (indentlevel == 0) if (!tok)
{ break;
insideLoop = false;
} continue;
}
else if (tok->str() == "for")
{
insideLoop = true;
} }
if (tok->str() != ",") if (tok->str() != ",")
@ -3306,7 +3304,7 @@ bool Tokenizer::simplifyComma()
{ {
for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous()) for (Token *tok2 = tok->previous(); tok2; tok2 = tok2->previous())
{ {
if (tok2->str() == "=" && !insideLoop) if (tok2->str() == "=")
{ {
// Handle "a = 0, b = 0;" // Handle "a = 0, b = 0;"
tok->str(";"); tok->str(";");