Refactoring: Use STL algorithms

This commit is contained in:
Daniel Marjamäki 2019-04-28 07:30:17 +02:00
parent c8dce14303
commit 69faa0d8c8
1 changed files with 12 additions and 15 deletions

View File

@ -924,11 +924,10 @@ public:
const ValueFlow::Value * getValue(const MathLib::bigint val) const {
if (!mImpl->mValues)
return nullptr;
for (const ValueFlow::Value &value : *mImpl->mValues) {
if (value.isIntValue() && value.intvalue == val)
return &value;
}
return nullptr;
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [=](const ValueFlow::Value &value) {
return value.isIntValue() && value.intvalue == val;
});
return it == mImpl->mValues->end() ? nullptr : &*it;;
}
const ValueFlow::Value * getMaxValue(bool condition) const {
@ -948,11 +947,10 @@ public:
const ValueFlow::Value * getMovedValue() const {
if (!mImpl->mValues)
return nullptr;
for (const ValueFlow::Value &value : *mImpl->mValues) {
if (value.isMovedValue() && value.moveKind != ValueFlow::Value::NonMovedVariable)
return &value;
}
return nullptr;
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [](const ValueFlow::Value &value) {
return value.isMovedValue() && value.moveKind != ValueFlow::Value::NonMovedVariable;
});
return it == mImpl->mValues->end() ? nullptr : &*it;;
}
const ValueFlow::Value * getValueLE(const MathLib::bigint val, const Settings *settings) const;
@ -963,11 +961,10 @@ public:
const ValueFlow::Value * getContainerSizeValue(const MathLib::bigint val) const {
if (!mImpl->mValues)
return nullptr;
for (const ValueFlow::Value &value : *mImpl->mValues) {
if (value.isContainerSizeValue() && value.intvalue == val)
return &value;
}
return nullptr;
const auto it = std::find_if(mImpl->mValues->begin(), mImpl->mValues->end(), [=](const ValueFlow::Value &value) {
return value.isContainerSizeValue() && value.intvalue == val;
});
return it == mImpl->mValues->end() ? nullptr : &*it;;
}
const Token *getValueTokenMaxStrLength() const;