[llvm] [ADT] Fix llvm::join on containers of char*s (PR #67113)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 07:54:06 PDT 2023


================
@@ -417,8 +418,13 @@ inline std::string join_impl(IteratorT Begin, IteratorT End,
     return S;
 
   size_t Len = (std::distance(Begin, End) - 1) * Separator.size();
-  for (IteratorT I = Begin; I != End; ++I)
-    Len += (*I).size();
+  for (IteratorT I = Begin; I != End; ++I) {
+    if constexpr (std::is_same_v<std::remove_reference_t<decltype(*I)>,
+                                 const char *>)
+      Len += strlen(*I);
+    else
+      Len += (*I).size();
----------------
kuhar wrote:

Who about constructing a temporary StringRef and calling .size()?

https://github.com/llvm/llvm-project/pull/67113


More information about the llvm-commits mailing list