Skip to content

Commit 0d4c388

Browse files
authored
Merge pull request #1166 from PowerGridModel/fix/batch-error-handling-performance
Performance: reduce copying during batch error handling
2 parents 5b2dbff + a479fd6 commit 0d4c388

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

power_grid_model_c/power_grid_model/include/power_grid_model/job_dispatch.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,20 @@ class JobDispatch {
184184
}
185185

186186
static void handle_batch_exceptions(std::vector<std::string> const& exceptions) {
187-
std::string combined_error_message;
187+
std::ostringstream combined_error_message;
188188
IdxVector failed_scenarios;
189189
std::vector<std::string> err_msgs;
190190
for (Idx batch = 0; batch < static_cast<Idx>(exceptions.size()); ++batch) {
191191
// append exception if it is not empty
192192
if (!exceptions[batch].empty()) {
193-
combined_error_message =
194-
std::format("{}Error in batch #{}: {}\n", combined_error_message, batch, exceptions[batch]);
193+
combined_error_message << std::format("Error in batch #{}: {}\n", batch, exceptions[batch]);
195194
failed_scenarios.push_back(batch);
196195
err_msgs.push_back(exceptions[batch]);
197196
}
198197
}
199-
if (!combined_error_message.empty()) {
200-
throw BatchCalculationError(combined_error_message, failed_scenarios, err_msgs);
198+
if (!combined_error_message.view().empty()) {
199+
throw BatchCalculationError(std::move(combined_error_message).str(), std::move(failed_scenarios),
200+
std::move(err_msgs));
201201
}
202202
}
203203
};

0 commit comments

Comments
 (0)