Refactorizations:

- Improve performance of simplifyTypedef by using Token::simpleMatch by ~15%
- Simplified code in simplifyTypedef
- Ran AStyle
This commit is contained in:
PKEuS 2015-12-02 23:32:50 +01:00
parent 7ea9e3ca4f
commit b8d39a2229
2 changed files with 18 additions and 19 deletions

View File

@ -2433,7 +2433,7 @@ void CheckOther::checkInterlockedDecrement()
} else if (Token::Match(ifEndTok, "} else { return %name%")) { } else if (Token::Match(ifEndTok, "} else { return %name%")) {
const Token* secondAccessTok = ifEndTok->tokAt(4); const Token* secondAccessTok = ifEndTok->tokAt(4);
if (secondAccessTok->str() == firstAccessTok->str()) { if (secondAccessTok->str() == firstAccessTok->str()) {
raceAfterInterlockedDecrementError( secondAccessTok ); raceAfterInterlockedDecrementError(secondAccessTok);
} }
} }
} }

View File

@ -1039,7 +1039,7 @@ void Tokenizer::simplifyTypedef()
while (!done) { while (!done) {
std::string pattern = typeName->str(); std::string pattern = typeName->str();
int scope = 0; unsigned int scope = 0;
bool simplifyType = false; bool simplifyType = false;
bool inMemberFunc = false; bool inMemberFunc = false;
int memberScope = 0; int memberScope = 0;
@ -1069,33 +1069,32 @@ void Tokenizer::simplifyTypedef()
pattern += typeName->str(); pattern += typeName->str();
} else { } else {
--scope; if (scope == 0)
if (scope < 0)
break; break;
--scope;
} }
} }
// check for member functions // check for member functions
else if (isCPP() && Token::Match(tok2, ") const| {")) { else if (isCPP() && Token::Match(tok2, ") const| {")) {
const Token *func = tok2->link()->previous(); const Token *func = tok2->link()->previous();
if (!func) if (!func || !func->previous()) // Ticket #4239
continue; continue;
if (func->previous()) { // Ticket #4239 /** @todo add support for multi-token operators */
/** @todo add support for multi-token operators */ if (func->previous()->str() == "operator")
if (func->previous()->str() == "operator") func = func->previous();
func = func->previous();
if (!func->previous()) // #7020 if (!func->previous()) // #7020
syntaxError(func); syntaxError(func);
// check for qualifier
if (func->previous()->str() == "::") { // check for qualifier
// check for available and matching class name if (func->previous()->str() == "::") {
if (!spaceInfo.empty() && classLevel < spaceInfo.size() && // check for available and matching class name
func->strAt(-2) == spaceInfo[classLevel].className) { if (!spaceInfo.empty() && classLevel < spaceInfo.size() &&
memberScope = 0; func->strAt(-2) == spaceInfo[classLevel].className) {
inMemberFunc = true; memberScope = 0;
} inMemberFunc = true;
} }
} }
} }