From a96f47a1f9e3343b0d164e636ba2cab0d20d27f6 Mon Sep 17 00:00:00 2001 From: Andreas Eknes Lie Date: Tue, 29 Aug 2023 14:45:49 +0200 Subject: [PATCH] Refactor join function --- src/clib/lib/job_queue/slurm_driver.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/clib/lib/job_queue/slurm_driver.cpp b/src/clib/lib/job_queue/slurm_driver.cpp index df872737fc4..e0fda5d88d0 100644 --- a/src/clib/lib/job_queue/slurm_driver.cpp +++ b/src/clib/lib/job_queue/slurm_driver.cpp @@ -161,26 +161,26 @@ static std::string load_stdout(const char *cmd, static std::vector split_string(const std::string &string_value) { std::vector strings; + std::size_t offset = string_value.find_first_not_of(", "); while (offset != std::string::npos) { auto item_end = string_value.find_first_of(", ", offset); strings.push_back(string_value.substr(offset, item_end - offset)); offset = string_value.find_first_not_of(", ", item_end); } + return strings; } template static std::string join_string(const C &strings) { - const std::string sep = ","; - std::string full_string; - bool first = true; - for (const auto &s : strings) { - if (!first) - full_string += sep; - full_string += s; - first = false; + std::string str; + + for (const auto &key : strings) { + str.append(","); + str.append(key); } - return full_string; + + return str.substr(str.find_first_not_of(',')); } void *slurm_driver_alloc() {