From ae76d0c3f0d79e2b8b389ba40a98c413bfef6a64 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com>
Date: Tue, 25 May 2021 17:51:58 -0400
Subject: [PATCH] string_utils: don't copy set in string_join, use {fmt}

Change-Id: Ibab897b53868091e55f092ccf1bc9a016de467b6
---
 src/string_utils.cpp | 10 +++-------
 src/string_utils.h   |  2 +-
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/string_utils.cpp b/src/string_utils.cpp
index 9a2a9bf0e4..801261fd05 100644
--- a/src/string_utils.cpp
+++ b/src/string_utils.cpp
@@ -22,6 +22,7 @@
 #include "string_utils.h"
 
 #include <fmt/core.h>
+#include <fmt/ranges.h>
 
 #include <sstream>
 #include <cctype>
@@ -146,14 +147,9 @@ string_remove_suffix(std::string_view str, char separator)
 }
 
 std::string
-string_join(std::set<std::string> set, std::string_view separator)
+string_join(const std::set<std::string>& set, std::string_view separator)
 {
-    if (set.empty())
-        return "";
-    std::string output;
-    for (const auto &s : set)
-        output += s+separator;
-    return output;
+    return fmt::format("{}", fmt::join(set, separator));
 }
 
 std::set<std::string>
diff --git a/src/string_utils.h b/src/string_utils.h
index b2b10c4b7b..c229638345 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -178,7 +178,7 @@ void string_replace(std::string& str, const std::string& from, const std::string
 
 std::string_view string_remove_suffix(std::string_view str, char separator);
 
-std::string string_join(std::set<std::string> set, std::string_view separator = "/");
+std::string string_join(const std::set<std::string>& set, std::string_view separator = "/");
 
 std::set<std::string> string_split_set(std::string& str, std::string_view separator = "/");
 
-- 
GitLab