[llvm-dev] RFC: Constructing StringRefs at compile time
James Y Knight via llvm-dev
llvm-dev at lists.llvm.org
Fri Dec 2 09:12:15 PST 2016
On Fri, Dec 2, 2016 at 6:35 AM, Malcolm Parsons via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> On 29 November 2016 at 17:52, Malcolm Parsons <malcolm.parsons at gmail.com>
> wrote:
> > On 29 November 2016 at 17:38, Zachary Turner <zturner at google.com> wrote:
> >> I see, but I looked over your proposed implementation from earlier in
> the
> >> thread, and if I'm not mistaken I see this:
> >
> > That's a different suggestion.
>
> llvm_strlen could be something like this:
>
> #if __cpp_lib_constexpr_char_traits
> constexpr size_t llvm_strlen(const char *S) {
> return std::char_traits<char>::length(S);
> }
> #elif __has_builtin(__builtin_strlen) || defined(__GNUC__)
> constexpr size_t llvm_strlen(const char *S) { return __builtin_strlen(S); }
> #elif __cpp_constexpr >= 201304
> constexpr size_t llvm_strlen(const char *S) {
> const char *const A = S;
> while (*S != '\0') {
> ++S;
> }
> return S - A;
> }
> #else
> constexpr size_t llvm_strlen(const char *S, size_t L = 0) {
> return *S ? llvm_strlen(S + 1, L + 1) : L;
> }
> #endif
>
...and we've gone in a loop in this conversation, haven't we? Isn't this
again where you end up with really slow code for compilers that end up in
the last #else, such as MSVC?
+1 from me for the StringLiteral proposal from a few messages back.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161202/248eb92b/attachment.html>
More information about the llvm-dev
mailing list