From f96484b60972e608c4e1f9027a8f8fe5f0558d17 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 8 Dec 2015 10:36:03 +0300 Subject: [PATCH] Cache and reuse value --- lib/tokenize.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 31c513cec..f073c9854 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1734,9 +1734,10 @@ bool Tokenizer::tokenize(std::istream &code, for (std::size_t i = 0; i < _symbolDatabase->getVariableListSize(); i++) { const Variable* var = _symbolDatabase->getVariableFromVarId(i); if (var && var->isRValueReference()) { - const_cast(var->typeEndToken())->str("&"); - const_cast(var->typeEndToken())->insertToken("&"); - const_cast(var->typeEndToken()->next())->scope(var->typeEndToken()->scope()); + Token* endTok = const_cast(var->typeEndToken()); + endTok->str("&"); + endTok->insertToken("&"); + endTok->next()->scope(endTok->scope()); } } @@ -2100,10 +2101,11 @@ void Tokenizer::simplifyArrayAccessSyntax() // 0[a] -> a[0] for (Token *tok = list.front(); tok; tok = tok->next()) { if (tok->isNumber() && Token::Match(tok, "%num% [ %name% ]")) { - std::string temp = tok->str(); - tok->str(tok->strAt(2)); - tok->varId(tok->tokAt(2)->varId()); - tok->tokAt(2)->str(temp); + const std::string number(tok->str()); + Token* indexTok = tok->tokAt(2); + tok->str(indexTok->str()); + tok->varId(indexTok->varId()); + indexTok->str(number); } } }