Optimization: Save 2 of 3 token list iterations in Tokenizer::simplifyStaticConst()
This commit is contained in:
parent
16e1e1d8f9
commit
a16e99c710
|
@ -5989,8 +5989,9 @@ void Tokenizer::simplifyStaticConst()
|
||||||
|
|
||||||
// Move 'const' before all other qualifiers and types and then
|
// Move 'const' before all other qualifiers and types and then
|
||||||
// move 'static' before all other qualifiers and types, ...
|
// move 'static' before all other qualifiers and types, ...
|
||||||
for (size_t i = 0; i < sizeof(qualifiers)/sizeof(qualifiers[0]); i++) {
|
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
bool continue2 = false;
|
||||||
|
for (size_t i = 0; i < sizeof(qualifiers)/sizeof(qualifiers[0]); i++) {
|
||||||
|
|
||||||
// Keep searching for a qualifier
|
// Keep searching for a qualifier
|
||||||
if (!tok->next() || tok->next()->str() != qualifiers[i])
|
if (!tok->next() || tok->next()->str() != qualifiers[i])
|
||||||
|
@ -6000,14 +6001,17 @@ void Tokenizer::simplifyStaticConst()
|
||||||
Token* leftTok = tok;
|
Token* leftTok = tok;
|
||||||
for (; leftTok; leftTok = leftTok->previous()) {
|
for (; leftTok; leftTok = leftTok->previous()) {
|
||||||
if (!Token::Match(leftTok, "%type%|static|const|extern|struct|::") ||
|
if (!Token::Match(leftTok, "%type%|static|const|extern|struct|::") ||
|
||||||
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator")))
|
(isCPP() && Token::Match(leftTok, "private:|protected:|public:|operator"))) {
|
||||||
|
continue2 = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The token preceding the declaration should indicate the start of a declaration
|
// The token preceding the declaration should indicate the start of a declaration
|
||||||
if (leftTok == tok ||
|
if (leftTok == tok ||
|
||||||
(leftTok && !Token::Match(leftTok, ";|{|}|(|,|private:|protected:|public:"))) {
|
(leftTok && !Token::Match(leftTok, ";|{|}|(|,|private:|protected:|public:"))) {
|
||||||
continue;
|
continue2 = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move the qualifier to the left-most position in the declaration
|
// Move the qualifier to the left-most position in the declaration
|
||||||
|
@ -6015,12 +6019,18 @@ void Tokenizer::simplifyStaticConst()
|
||||||
if (!leftTok) {
|
if (!leftTok) {
|
||||||
list.front()->insertToken(qualifiers[i], emptyString, false);
|
list.front()->insertToken(qualifiers[i], emptyString, false);
|
||||||
list.front()->swapWithNext();
|
list.front()->swapWithNext();
|
||||||
} else if (leftTok->next())
|
tok = list.front();
|
||||||
|
} else if (leftTok->next()) {
|
||||||
leftTok->next()->insertToken(qualifiers[i], emptyString, true);
|
leftTok->next()->insertToken(qualifiers[i], emptyString, true);
|
||||||
else
|
tok = leftTok->next();
|
||||||
|
} else {
|
||||||
leftTok->insertToken(qualifiers[i]);
|
leftTok->insertToken(qualifiers[i]);
|
||||||
|
tok = leftTok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (continue2)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::simplifyIfAndWhileAssign()
|
void Tokenizer::simplifyIfAndWhileAssign()
|
||||||
|
|
Loading…
Reference in New Issue