ProgramMemory: avoid unnecessary copy in `erase_if()`
-D__GNUC__ --check-level=exhaustive ../lib/utils.cpp
Clang 17 773,369,412 -> 772,984,251
GCC 14 794,493,015 -> 795,010,529
The example from https://trac.cppcheck.net/ticket/10765#comment:4:
Clang 17 3,988,168,871 -> 3,989,222,640
GCC 14 4,098,327,498 -> 4,100,109,857
I thought this improves things slightly. Seems like I misread the local results I had before. But maybe it will improve things if the use count thing is fixed...
The latest rework get rid of the unnecessary copy-on-writes and tries to minimizes the redundant work. Unfortunately this is not really faster at all with few conditions - needs some more looking at with more complex code though.
It exposed an issue with std::find_if though with the unexpected copies of objects which needs to be looked into.
It exposed an issue with
std::find_ifthough with the unexpected copies of objects which needs to be looked into.
auto it = std::find_if(mValues->cbegin(), mValues->cend(), [&pred](const decltype(mValues->cbegin())::value_type& entry) {
return pred(entry.first);
});
The actual type provided by this is std::pair<const ExprIdToken, ValueFlow::Value>. The missing const on the first type is causing the copies.
The actual type provided by this is
std::pair<const ExprIdToken, ValueFlow::Value>. The missingconston the first type is causing the copies.
I filed an upstream ticket about detecting this: https://github.com/llvm/llvm-project/issues/104572. Still need to file one about detecting it ourselves.
This greatly reduces the amount of copies but in the used test cases it does not translate into any visible improvements. Let's see what the selfcheck says.