Use static array to store iterator infer models instead of constructing a vector everytime (#3539)

This commit is contained in:
Paul Fultz II 2021-11-01 13:18:18 -05:00 committed by GitHub
parent 54d621555d
commit 04ecf53a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -101,6 +101,7 @@
#include "valueptr.h"
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstddef>
@ -5538,8 +5539,9 @@ static void valueFlowInferCondition(TokenList* tokenlist,
setTokenValue(tok, value, settings);
} else if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
for (ValuePtr<InferModel> model :
std::vector<ValuePtr<InferModel>>{EndIteratorInferModel{}, StartIteratorInferModel{}}) {
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
StartIteratorInferModel{}};
for (const ValuePtr<InferModel>& model : iteratorModels) {
std::vector<ValueFlow::Value> result =
infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());
for (ValueFlow::Value value : result) {