Optimization: Improved performance of simplifyTypedef for code with lots of typedefs

20% performance gain when checking ExtremeTuxRacer sourcecode (with glext.h available)
This commit is contained in:
PKEuS 2020-05-13 19:06:54 +02:00
parent e9318d7bfc
commit d6390dbd14
2 changed files with 10 additions and 25 deletions

View File

@ -747,33 +747,17 @@ void Tokenizer::simplifyTypedef()
if (!tokOffset)
syntaxError(tok);
if (Token::Match(tokOffset, "%type%")) {
if (tokOffset->isName() && !tokOffset->isKeyword()) {
// found the type name
typeName = tokOffset;
tokOffset = tokOffset->next();
// check for array
if (tokOffset && tokOffset->str() == "[") {
arrayStart = tokOffset;
bool atEnd = false;
while (!atEnd) {
while (tokOffset->next() && !Token::Match(tokOffset->next(), ";|,")) {
tokOffset = tokOffset->next();
}
if (!tokOffset->next())
return; // invalid input
else if (tokOffset->next()->str() == ";")
atEnd = true;
else if (tokOffset->str() == "]")
atEnd = true;
else
tokOffset = tokOffset->next();
}
arrayEnd = tokOffset;
tokOffset = tokOffset->next();
while (tokOffset && tokOffset->str() == "[") {
if (!arrayStart)
arrayStart = tokOffset;
arrayEnd = tokOffset->link();
tokOffset = arrayEnd->next();
}
// check for end or another
@ -1134,8 +1118,9 @@ void Tokenizer::simplifyTypedef()
}
// check for typedef that can be substituted
else if (Token::simpleMatch(tok2, pattern.c_str()) ||
(inMemberFunc && tok2->str() == typeName->str())) {
else if (tok2->isNameOnly() &&
(Token::simpleMatch(tok2, pattern.c_str()) ||
(inMemberFunc && tok2->str() == typeName->str()))) {
// member function class variables don't need qualification
if (!(inMemberFunc && tok2->str() == typeName->str()) && pattern.find("::") != std::string::npos) { // has a "something ::"
Token *start = tok2;

View File

@ -2896,7 +2896,7 @@ private:
"struct S {\n"
" _Atomic union { int n; };\n"
"};");
ASSERT_EQUALS("", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (debug) Failed to parse 'typedef _Atomic ( int ) & atomic_int_ref ;'. The checking continues anyway.\n", errout.str());
}
void symboldatabase35() { // ticket #4806 and #4841