summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--absl/strings/internal/str_join_internal.h10
-rw-r--r--absl/strings/str_join.h3
-rw-r--r--absl/strings/str_join_benchmark.cc10
3 files changed, 22 insertions, 1 deletions
diff --git a/absl/strings/internal/str_join_internal.h b/absl/strings/internal/str_join_internal.h
index 440d47ff..3e730c7a 100644
--- a/absl/strings/internal/str_join_internal.h
+++ b/absl/strings/internal/str_join_internal.h
@@ -33,6 +33,7 @@
#include <cstdint>
#include <cstring>
+#include <initializer_list>
#include <iterator>
#include <limits>
#include <memory>
@@ -321,6 +322,15 @@ std::string JoinRange(const Range& range, absl::string_view separator) {
return JoinRange(begin(range), end(range), separator);
}
+template <typename Tuple, std::size_t... I>
+std::string JoinTuple(const Tuple& value, absl::string_view separator,
+ std::index_sequence<I...>) {
+ return JoinRange(
+ std::initializer_list<absl::string_view>{
+ static_cast<const AlphaNum&>(std::get<I>(value)).Piece()...},
+ separator);
+}
+
} // namespace strings_internal
ABSL_NAMESPACE_END
} // namespace absl
diff --git a/absl/strings/str_join.h b/absl/strings/str_join.h
index badc944a..8d7bc6ba 100644
--- a/absl/strings/str_join.h
+++ b/absl/strings/str_join.h
@@ -291,7 +291,8 @@ inline std::string StrJoin(std::initializer_list<absl::string_view> il,
template <typename... T>
std::string StrJoin(const std::tuple<T...>& value,
absl::string_view separator) {
- return strings_internal::JoinAlgorithm(value, separator, AlphaNumFormatter());
+ return strings_internal::JoinTuple(value, separator,
+ std::index_sequence_for<T...>{});
}
ABSL_NAMESPACE_END
diff --git a/absl/strings/str_join_benchmark.cc b/absl/strings/str_join_benchmark.cc
index d6f689ff..be7a7257 100644
--- a/absl/strings/str_join_benchmark.cc
+++ b/absl/strings/str_join_benchmark.cc
@@ -16,6 +16,7 @@
#include "absl/strings/str_join.h"
#include <string>
+#include <tuple>
#include <vector>
#include <utility>
@@ -94,4 +95,13 @@ BENCHMARK(BM_JoinStreamable)
->ArgPair(16, 256)
->ArgPair(256, 256);
+void BM_JoinTuple(benchmark::State& state) {
+ for (auto _ : state) {
+ std::string s =
+ absl::StrJoin(std::make_tuple(123456789, 987654321, 24680, 13579), "/");
+ benchmark::DoNotOptimize(s);
+ }
+}
+BENCHMARK(BM_JoinTuple);
+
} // namespace