Skip to content

Commit f96484b

Browse files
committed
Cache and reuse value
1 parent ca3c19c commit f96484b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

lib/tokenize.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,9 +1734,10 @@ bool Tokenizer::tokenize(std::istream &code,
17341734
for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) {
17351735
const Variable* var = _symbolDatabase->getVariableFromVarId(i);
17361736
if (var && var->isRValueReference()) {
1737-
const_cast<Token*>(var->typeEndToken())->str("&");
1738-
const_cast<Token*>(var->typeEndToken())->insertToken("&");
1739-
const_cast<Token*>(var->typeEndToken()->next())->scope(var->typeEndToken()->scope());
1737+
Token* endTok = const_cast<Token*>(var->typeEndToken());
1738+
endTok->str("&");
1739+
endTok->insertToken("&");
1740+
endTok->next()->scope(endTok->scope());
17401741
}
17411742
}
17421743

@@ -2100,10 +2101,11 @@ void Tokenizer::simplifyArrayAccessSyntax()
21002101
// 0[a] -> a[0]
21012102
for (Token *tok = list.front(); tok; tok = tok->next()) {
21022103
if (tok->isNumber() && Token::Match(tok, "%num% [ %name% ]")) {
2103-
std::string temp = tok->str();
2104-
tok->str(tok->strAt(2));
2105-
tok->varId(tok->tokAt(2)->varId());
2106-
tok->tokAt(2)->str(temp);
2104+
const std::string number(tok->str());
2105+
Token* indexTok = tok->tokAt(2);
2106+
tok->str(indexTok->str());
2107+
tok->varId(indexTok->varId());
2108+
indexTok->str(number);
21072109
}
21082110
}
21092111
}

0 commit comments

Comments
 (0)