Skip to content

Commit 32898dc

Browse files
roberthtrofi
authored andcommitted
nix-util: Use small_vector in concatMapStringsSep
1 parent f3dbaa3 commit 32898dc

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/libutil/strings.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ basicSplitString(std::basic_string_view<OsChar> s, std::basic_string_view<OsChar
3939
template std::string concatStringsSep(std::string_view, const std::list<std::string> &);
4040
template std::string concatStringsSep(std::string_view, const std::set<std::string> &);
4141
template std::string concatStringsSep(std::string_view, const std::vector<std::string> &);
42+
template std::string concatStringsSep(std::string_view, const boost::container::small_vector<std::string, 64> &);
4243

4344
typedef std::string_view strings_2[2];
4445
template std::string concatStringsSep(std::string_view, const strings_2 &);

src/libutil/strings.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include <string>
77
#include <vector>
88

9+
#include <boost/container/small_vector.hpp>
10+
911
namespace nix {
1012

1113
/*
@@ -54,14 +56,15 @@ std::string concatStringsSep(const std::string_view sep, const C & ss);
5456
extern template std::string concatStringsSep(std::string_view, const std::list<std::string> &);
5557
extern template std::string concatStringsSep(std::string_view, const std::set<std::string> &);
5658
extern template std::string concatStringsSep(std::string_view, const std::vector<std::string> &);
59+
extern template std::string concatStringsSep(std::string_view, const boost::container::small_vector<std::string, 64> &);
5760

5861
/**
5962
* Apply a function to the `iterable`'s items and concat them with `separator`.
6063
*/
6164
template<class C, class F>
6265
std::string concatMapStringsSep(std::string_view separator, const C & iterable, F fn)
6366
{
64-
std::vector<std::string> strings;
67+
boost::container::small_vector<std::string, 64> strings;
6568
strings.reserve(iterable.size());
6669
for (const auto & elem : iterable) {
6770
strings.push_back(fn(elem));

0 commit comments

Comments
 (0)