@@ -60,7 +60,11 @@ namespace llvm {
60
60
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
61
61
62
62
private:
63
- std::string_view View;
63
+ // / The start of the string, in an external buffer.
64
+ const char *Data = nullptr ;
65
+
66
+ // / The length of the string.
67
+ size_t Length = 0 ;
64
68
65
69
// Workaround memcmp issue with null pointers (undefined behavior)
66
70
// by providing a specialized version
@@ -82,26 +86,28 @@ namespace llvm {
82
86
83
87
// / Construct a string ref from a cstring.
84
88
/* implicit*/ constexpr StringRef (const char *Str LLVM_LIFETIME_BOUND)
85
- : View (Str, Str ?
89
+ : Data (Str), Length( Str ?
86
90
// GCC 7 doesn't have constexpr char_traits. Fall back to __builtin_strlen.
87
91
#if defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE < 8
88
- __builtin_strlen (Str)
92
+ __builtin_strlen (Str)
89
93
#else
90
- std::char_traits<char >::length(Str)
94
+ std::char_traits<char >::length(Str)
91
95
#endif
92
- : 0 ) {
96
+ : 0 ) {
93
97
}
94
98
95
99
// / Construct a string ref from a pointer and length.
96
100
/* implicit*/ constexpr StringRef (const char *data LLVM_LIFETIME_BOUND,
97
101
size_t length)
98
- : View (data, length) {}
102
+ : Data (data), Length( length) {}
99
103
100
104
// / Construct a string ref from an std::string.
101
- /* implicit*/ StringRef(const std::string &Str) : View(Str) {}
105
+ /* implicit*/ StringRef(const std::string &Str)
106
+ : Data(Str.data()), Length(Str.length()) {}
102
107
103
108
// / Construct a string ref from an std::string_view.
104
- /* implicit*/ constexpr StringRef (std::string_view Str) : View(Str) {}
109
+ /* implicit*/ constexpr StringRef (std::string_view Str)
110
+ : Data(Str.data()), Length(Str.size()) {}
105
111
106
112
// / @}
107
113
// / @name Iterators
@@ -135,13 +141,13 @@ namespace llvm {
135
141
136
142
// / data - Get a pointer to the start of the string (which may not be null
137
143
// / terminated).
138
- [[nodiscard]] constexpr const char *data () const { return View. data () ; }
144
+ [[nodiscard]] constexpr const char *data () const { return Data ; }
139
145
140
146
// / empty - Check if the string is empty.
141
147
[[nodiscard]] constexpr bool empty () const { return size () == 0 ; }
142
148
143
149
// / size - Get the string size.
144
- [[nodiscard]] constexpr size_t size () const { return View. size () ; }
150
+ [[nodiscard]] constexpr size_t size () const { return Length ; }
145
151
146
152
// / front - Get the first character in the string.
147
153
[[nodiscard]] char front () const {
0 commit comments