[llvm] [ADT] Fix llvm::join on containers of char*s (PR #67113)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 12:08:26 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();
----------------
dwblaikie wrote:
> Sure, constructing a temporary StringRef would work too, what's the difference?
It does allow the implementation to remain generic, if somewhat more subtle than it currently is.
> > any chance of using StringRef in the callers? Rather than having more places dealing with null terminated strings?
>
> Converting Driver and others to use StringRef seems like a helpful project, though not one I personally have time for. Having a few functions not work with `char*` doesn't seem like a useful state in the meanwhile, but I already wrote the concat-loop where this was actually needed, so I can drop this if we'd rather not have it.
*nod* I'm more comfortable with it with the StringRef/generic implementation. "supports anything that's StringRef-able" sounds OK to me.
https://github.com/llvm/llvm-project/pull/67113
More information about the llvm-commits
mailing list