zturner added a comment.
In response to all the questions about "Will a StringRef constructor be called
on XXX", the answer is usually yes, but the constructor will be inlined and
invoke `__builtin_strlen` (which is constexpr on GCC and Clang) when used on a
string literal. In other words, there is zero overhead.
So the code generated for `S.startswith("--")` will end up just being `(2 >=
S.Length) && (::memcmp(S.Data, "--", 2) == 0)`.
The only time we have to worry about constexprness and make sure we use
`StringLiteral` is with static variables (global or local). With static
variables, the compiler has to decide between static link-time initialization
or runtime initialization, and only if you declare the variable as `constexpr`
will it choose link-time initialization. So the generated code for these two
might look something like this:
// No generated code, S is initialized at link-time.
constexpr StringLiteral S("foo");
// mov <addr-of-T.Data>, <addr-of-global-string>
// mov <addr-of-T.Length>, 3
StringLiteral T("foo");
https://reviews.llvm.org/D27780
_______________________________________________
lldb-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits