Skip to content

Commit 04ecf53

Browse files
authored
Use static array to store iterator infer models instead of constructing a vector everytime (#3539)
1 parent 54d6215 commit 04ecf53

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/valueflow.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
#include "valueptr.h"
102102

103103
#include <algorithm>
104+
#include <array>
104105
#include <cassert>
105106
#include <cmath>
106107
#include <cstddef>
@@ -5538,8 +5539,9 @@ static void valueFlowInferCondition(TokenList* tokenlist,
55385539
setTokenValue(tok, value, settings);
55395540
} else if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
55405541
if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
5541-
for (ValuePtr<InferModel> model :
5542-
std::vector<ValuePtr<InferModel>>{EndIteratorInferModel{}, StartIteratorInferModel{}}) {
5542+
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
5543+
StartIteratorInferModel{}};
5544+
for (const ValuePtr<InferModel>& model : iteratorModels) {
55435545
std::vector<ValueFlow::Value> result =
55445546
infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());
55455547
for (ValueFlow::Value value : result) {

0 commit comments

Comments
 (0)