Skip to content

Commit 558a2f0

Browse files
committed
SymbolDatabase::createSymbolDatabaseFindAllScopes(): hoist _tokenizer->isC(PP) dereference out of loop.
1 parent e187fdb commit 558a2f0

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ static const Token* skipScopeIdentifiers(const Token* tok)
8282

8383
void SymbolDatabase::createSymbolDatabaseFindAllScopes()
8484
{
85+
const bool isCPP = _tokenizer->isCPP();
86+
const bool isC = _tokenizer->isC();
87+
8588
// create global scope
8689
scopeList.emplace_back(this, nullptr, nullptr);
8790

@@ -99,16 +102,16 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
99102
"SymbolDatabase",
100103
tok->progressValue());
101104
// Locate next class
102-
if ((_tokenizer->isCPP() && ((Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") &&
105+
if ((isCPP && ((Token::Match(tok, "class|struct|union|namespace ::| %name% {|:|::|<") &&
103106
!Token::Match(tok->previous(), "new|friend|const|enum|typedef|mutable|volatile|)|(|<")) ||
104107
(Token::Match(tok, "enum class| %name% {") ||
105108
Token::Match(tok, "enum class| %name% : %name% {"))))
106-
|| (_tokenizer->isC() && Token::Match(tok, "struct|union|enum %name% {"))) {
109+
|| (isC && Token::Match(tok, "struct|union|enum %name% {"))) {
107110
const Token *tok2 = tok->tokAt(2);
108111

109112
if (tok->strAt(1) == "::")
110113
tok2 = tok2->next();
111-
else if (_tokenizer->isCPP() && tok->strAt(1) == "class")
114+
else if (isCPP && tok->strAt(1) == "class")
112115
tok2 = tok2->next();
113116

114117
while (Token::Match(tok2, ":: %name%"))
@@ -124,7 +127,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
124127
}
125128

126129
// skip over final
127-
if (_tokenizer->isCPP() && Token::simpleMatch(tok2, "final"))
130+
if (isCPP && Token::simpleMatch(tok2, "final"))
128131
tok2 = tok2->next();
129132

130133
// make sure we have valid code
@@ -192,7 +195,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
192195
}
193196

194197
// definition may be different than declaration
195-
if (_tokenizer->isCPP() && tok->str() == "class") {
198+
if (isCPP && tok->str() == "class") {
196199
access[new_scope] = Private;
197200
new_scope->type = Scope::eClass;
198201
} else if (tok->str() == "struct") {
@@ -269,7 +272,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
269272
}
270273

271274
// Namespace and unknown macro (#3854)
272-
else if (_tokenizer->isCPP() &&
275+
else if (isCPP &&
273276
Token::Match(tok, "namespace %name% %type% (") &&
274277
tok->tokAt(2)->isUpperCaseName() &&
275278
Token::simpleMatch(tok->linkAt(3), ") {")) {
@@ -309,7 +312,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
309312
}
310313

311314
// using namespace
312-
else if (_tokenizer->isCPP() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
315+
else if (isCPP && Token::Match(tok, "using namespace ::| %type% ;|::")) {
313316
Scope::UsingInfo using_info;
314317

315318
using_info.start = tok; // save location
@@ -329,7 +332,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
329332
}
330333

331334
// using type alias
332-
else if (_tokenizer->isCPP() && Token::Match(tok, "using %name% =")) {
335+
else if (isCPP && Token::Match(tok, "using %name% =")) {
333336
if (tok->strAt(-1) != ">" && !findType(tok->next(), scope)) {
334337
// fill typeList..
335338
typeList.emplace_back(tok, nullptr, scope);
@@ -533,7 +536,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
533536
}
534537

535538
// friend class declaration?
536-
else if (_tokenizer->isCPP() && Token::Match(tok, "friend class| ::| %any% ;|::")) {
539+
else if (isCPP && Token::Match(tok, "friend class| ::| %any% ;|::")) {
537540
Type::FriendInfo friendInfo;
538541

539542
// save the name start

0 commit comments

Comments
 (0)