Skip to content

Commit 9697e46

Browse files
[ADT] Simplify StringRef(const char *) (NFC) (#160038)
This patch delegates the string length computation to std::string_view. This way, we don't have to worry about old GCC versions or call __builtin_strlen on our own.
1 parent c0b6ddf commit 9697e46

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

llvm/include/llvm/ADT/StringRef.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,7 @@ namespace llvm {
9090

9191
/// Construct a string ref from a cstring.
9292
/*implicit*/ constexpr StringRef(const char *Str LLVM_LIFETIME_BOUND)
93-
: Data(Str), Length(Str ?
94-
// GCC 7 doesn't have constexpr char_traits. Fall back to __builtin_strlen.
95-
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8
96-
__builtin_strlen(Str)
97-
#else
98-
std::char_traits<char>::length(Str)
99-
#endif
100-
: 0) {
101-
}
93+
: StringRef(Str ? std::string_view(Str) : std::string_view()) {}
10294

10395
/// Construct a string ref from a pointer and length.
10496
/*implicit*/ constexpr StringRef(const char *data LLVM_LIFETIME_BOUND,

0 commit comments

Comments
 (0)