Skip to content

Commit 3c8f5b8

Browse files
committed
Refactorization: Allocate Token::_values (ValueFlow information) dynamically, reducing size of each token by around 10%
1 parent 2938278 commit 3c8f5b8

17 files changed

Lines changed: 190 additions & 152 deletions

lib/astutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static bool match(const Token *tok, const std::string &rhs)
8787
{
8888
if (tok->str() == rhs)
8989
return true;
90-
if (tok->isName() && !tok->varId() && tok->values.size() == 1U && tok->values.front().isKnown() && MathLib::toString(tok->values.front().intvalue) == rhs)
90+
if (tok->isName() && !tok->varId() && tok->values().size() == 1U && tok->values().front().isKnown() && MathLib::toString(tok->values().front().intvalue) == rhs)
9191
return true;
9292
return false;
9393
}

lib/checkautovariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ bool CheckAutoVariables::isAutoVarArray(const Token *tok)
119119

120120
// ValueFlow
121121
if (var->isPointer() && !var->isArgument()) {
122-
for (std::list<ValueFlow::Value>::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) {
122+
for (std::list<ValueFlow::Value>::const_iterator it = tok->values().begin(); it != tok->values().end(); ++it) {
123123
const ValueFlow::Value &val = *it;
124124
if (val.isTokValue() && isAutoVarArray(val.tokvalue))
125125
return true;

lib/checkbufferoverrun.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
11321132
if (!value)
11331133
continue;
11341134

1135-
for (std::list<ValueFlow::Value>::const_iterator it = tok->values.begin(); it != tok->values.end(); ++it) {
1135+
for (std::list<ValueFlow::Value>::const_iterator it = tok->values().begin(); it != tok->values().end(); ++it) {
11361136
if (!it->isTokValue() || !it->tokvalue)
11371137
continue;
11381138
const Variable *var = it->tokvalue->variable();

lib/checkcondition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ void CheckCondition::checkBadBitmaskCheck()
261261
(parent->str() == "(" && Token::Match(parent->astOperand1(), "if|while")) ||
262262
(parent->str() == "return" && parent->astOperand1() == tok && inBooleanFunction(tok));
263263

264-
const bool isTrue = (tok->astOperand1()->values.size() == 1 && tok->astOperand1()->values.front().intvalue != 0 && tok->astOperand1()->values.front().isKnown()) ||
265-
(tok->astOperand2()->values.size() == 1 && tok->astOperand2()->values.front().intvalue != 0 && tok->astOperand2()->values.front().isKnown());
264+
const bool isTrue = (tok->astOperand1()->values().size() == 1 && tok->astOperand1()->values().front().intvalue != 0 && tok->astOperand1()->values().front().isKnown()) ||
265+
(tok->astOperand2()->values().size() == 1 && tok->astOperand2()->values().front().intvalue != 0 && tok->astOperand2()->values().front().isKnown());
266266

267267
if (isBoolean && isTrue)
268268
badBitmaskCheckError(tok);
@@ -1049,7 +1049,7 @@ void CheckCondition::alwaysTrueFalse()
10491049
if (isExpandedMacro)
10501050
continue;
10511051

1052-
alwaysTrueFalseError(tok, tok->values.front().intvalue != 0);
1052+
alwaysTrueFalseError(tok, tok->values().front().intvalue != 0);
10531053
}
10541054
}
10551055
}

lib/checkio.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,8 @@ static bool findFormat(unsigned int arg, const Token *firstArg,
474474
argTok->variable()->dimensionKnown(0) &&
475475
argTok->variable()->dimension(0) != 0))) {
476476
*formatArgTok = argTok->nextArgument();
477-
if (!argTok->values.empty() && argTok->values.front().isTokValue() && argTok->values.front().tokvalue && argTok->values.front().tokvalue->tokType() == Token::eString)
478-
*formatStringTok = argTok->values.front().tokvalue;
477+
if (!argTok->values().empty() && argTok->values().front().isTokValue() && argTok->values().front().tokvalue && argTok->values().front().tokvalue->tokType() == Token::eString)
478+
*formatStringTok = argTok->values().front().tokvalue;
479479
return true;
480480
}
481481
return false;

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void CheckLeakAutoVar::functionCall(const Token *tok, VarInfo *varInfo, const Va
547547
if (arg->str() == "&")
548548
arg = arg->next();
549549

550-
bool isnull = arg->hasKnownIntValue() && arg->values.front().intvalue == 0;
550+
bool isnull = arg->hasKnownIntValue() && arg->values().front().intvalue == 0;
551551

552552
// Is variable allocated?
553553
if (!isnull && (!af || af->arg == argNr))

lib/checkmemoryleak.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,18 @@ static bool alwaysTrue(const Token *tok)
481481
{
482482
if (!tok)
483483
return false;
484-
if (tok->values.size() == 1U &&
485-
tok->values.front().intvalue != 0 &&
486-
tok->values.front().isKnown())
484+
if (tok->values().size() == 1U &&
485+
tok->values().front().intvalue != 0 &&
486+
tok->values().front().isKnown())
487487
return true;
488488
if (tok->str() == "||")
489489
return alwaysTrue(tok->astOperand1()) || alwaysTrue(tok->astOperand2());
490490
if (tok->str() == "true")
491491
return true;
492492
return (tok->isComparisonOp() &&
493-
tok->values.size() == 1U &&
494-
tok->values.front().isKnown() &&
495-
tok->values.front().intvalue != 0);
493+
tok->values().size() == 1U &&
494+
tok->values().front().isKnown() &&
495+
tok->values().front().intvalue != 0);
496496
}
497497

498498
bool CheckMemoryLeakInFunction::test_white_list(const std::string &funcname, const Settings *settings, bool cpp)

lib/checkother.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ void CheckOther::warningOldStylePointerCast()
284284
tok = tok->next();
285285

286286
const Token *p = tok->tokAt(4);
287-
if (p->hasKnownIntValue() && p->values.front().intvalue==0) // Casting nullpointers is safe
287+
if (p->hasKnownIntValue() && p->values().front().intvalue==0) // Casting nullpointers is safe
288288
continue;
289289

290290
// Is "type" a class?

lib/checktype.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void CheckType::checkFloatToIntegerOverflow()
337337
continue;
338338

339339
const Token *op1 = tok->astOperand1();
340-
for (std::list<ValueFlow::Value>::const_iterator it = op1->values.begin(); it != op1->values.end(); ++it) {
340+
for (std::list<ValueFlow::Value>::const_iterator it = op1->values().begin(); it != op1->values().end(); ++it) {
341341
if (it->valueType != ValueFlow::Value::FLOAT)
342342
continue;
343343
if (it->inconclusive && !_settings->inconclusive)

lib/checkuninitvar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::map<unsigned
219219
}
220220

221221
else if (tok->isComparisonOp()) {
222-
if (tok->values.size() == 1U && tok->values.front().isKnown()) {
223-
if (tok->values.front().intvalue)
222+
if (tok->values().size() == 1U && tok->values().front().isKnown()) {
223+
if (tok->values().front().intvalue)
224224
*alwaysTrue = true;
225225
else
226226
*alwaysFalse = true;

0 commit comments

Comments
 (0)