Don't Copy Only to Move Result

The original code here used move semantics to transfer ownership,
but commit 15cb87576 (PR #5874) switched to using the simpler
by-reference semantics instead.  Follow through on this change by
not creating an intermediate copy only to move that copy into
another object.  Instead, copy only the report objects when creating
the output requests.
This commit is contained in:
Bård Skaflestad committed 2025-03-17 14:14:21 +01:00
1 parent 8d5210e270
commit 73fdf8f5f4
1 file changed
+10 -7
@@ -29,6 +29,7 @@
#include <opm/simulators/flow/ConvergenceOutputConfiguration.hpp>
#include <algorithm>
#include <iterator>
#include <string_view>
#include <utility>
#include <vector>
@@ -74,16 +75,18 @@ write(const std::vector<StepReport>& reports)
return;
}
auto new_reports = std::vector<StepReport> {
reports.begin() + this->alreadyReportedSteps_, reports.end()
};
const auto begin = reports.begin() + this->alreadyReportedSteps_;
const auto end = reports.end();
auto requests = std::vector<ConvergenceReportQueue::OutputRequest>{};
requests.reserve(new_reports.size());
requests.reserve(std::distance(begin, end));
for (auto&& report : new_reports) {
requests.push_back({ report.report_step, report.current_step, std::move(report.report) });
}
std::transform(begin, end, std::back_inserter(requests),
[](const StepReport& report) {
return ConvergenceReportQueue::OutputRequest {
report.report_step, report.current_step, report.report
};
});
this->alreadyReportedSteps_ = reports.size();