blob: f8e9208462593eacc2d504b30a2a62279cb78ca0 [file] [log] [blame]
Daniel Dunbare6551282009-09-16 22:38:48 +00001//===-- StringRef.cpp - Lightweight String References ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/ADT/StringRef.h"
John McCall1e7ad392010-02-28 09:55:58 +000011#include "llvm/ADT/APInt.h"
Ted Kremenek13302ec2010-11-07 06:09:02 +000012#include "llvm/ADT/OwningPtr.h"
Chandler Carruth528f0bb2012-03-04 10:55:27 +000013#include "llvm/ADT/Hashing.h"
Kaelyn Uhrain01d53ec2012-02-15 22:13:07 +000014#include "llvm/ADT/edit_distance.h"
Michael J. Spencerb0940b42012-05-11 22:08:50 +000015
Benjamin Kramer250eb002010-08-23 18:16:08 +000016#include <bitset>
Douglas Gregorad6b6da2010-01-07 00:51:54 +000017
Daniel Dunbare6551282009-09-16 22:38:48 +000018using namespace llvm;
19
Daniel Dunbar77696be2009-09-22 03:34:40 +000020// MSVC emits references to this into the translation units which reference it.
21#ifndef _MSC_VER
Daniel Dunbare6551282009-09-16 22:38:48 +000022const size_t StringRef::npos;
Daniel Dunbar77696be2009-09-22 03:34:40 +000023#endif
Chris Lattnercea14382009-09-19 19:47:14 +000024
Benjamin Kramer05872ea2009-11-12 20:36:59 +000025static char ascii_tolower(char x) {
26 if (x >= 'A' && x <= 'Z')
27 return x - 'A' + 'a';
28 return x;
29}
30
Daniel Dunbar589fbb12011-11-06 18:04:43 +000031static char ascii_toupper(char x) {
32 if (x >= 'a' && x <= 'z')
33 return x - 'a' + 'A';
34 return x;
35}
36
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000037static bool ascii_isdigit(char x) {
38 return x >= '0' && x <= '9';
39}
40
Benjamin Kramer05872ea2009-11-12 20:36:59 +000041/// compare_lower - Compare strings, ignoring case.
42int StringRef::compare_lower(StringRef RHS) const {
Daniel Dunbar58ce7ac2009-11-19 18:53:18 +000043 for (size_t I = 0, E = min(Length, RHS.Length); I != E; ++I) {
Benjamin Kramer0043e352010-08-26 14:21:08 +000044 unsigned char LHC = ascii_tolower(Data[I]);
45 unsigned char RHC = ascii_tolower(RHS.Data[I]);
Benjamin Kramer05872ea2009-11-12 20:36:59 +000046 if (LHC != RHC)
47 return LHC < RHC ? -1 : 1;
48 }
49
50 if (Length == RHS.Length)
Benjamin Kramer0043e352010-08-26 14:21:08 +000051 return 0;
Benjamin Kramer05872ea2009-11-12 20:36:59 +000052 return Length < RHS.Length ? -1 : 1;
53}
54
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000055/// compare_numeric - Compare strings, handle embedded numbers.
56int StringRef::compare_numeric(StringRef RHS) const {
57 for (size_t I = 0, E = min(Length, RHS.Length); I != E; ++I) {
Jakob Stoklund Olesen7850dd02011-09-30 17:03:55 +000058 // Check for sequences of digits.
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000059 if (ascii_isdigit(Data[I]) && ascii_isdigit(RHS.Data[I])) {
Jakob Stoklund Olesen7850dd02011-09-30 17:03:55 +000060 // The longer sequence of numbers is considered larger.
61 // This doesn't really handle prefixed zeros well.
62 size_t J;
63 for (J = I + 1; J != E + 1; ++J) {
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000064 bool ld = J < Length && ascii_isdigit(Data[J]);
65 bool rd = J < RHS.Length && ascii_isdigit(RHS.Data[J]);
66 if (ld != rd)
67 return rd ? -1 : 1;
68 if (!rd)
69 break;
70 }
Jakob Stoklund Olesen7850dd02011-09-30 17:03:55 +000071 // The two number sequences have the same length (J-I), just memcmp them.
72 if (int Res = compareMemory(Data + I, RHS.Data + I, J - I))
73 return Res < 0 ? -1 : 1;
74 // Identical number sequences, continue search after the numbers.
75 I = J - 1;
76 continue;
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000077 }
Jakob Stoklund Olesen7850dd02011-09-30 17:03:55 +000078 if (Data[I] != RHS.Data[I])
79 return (unsigned char)Data[I] < (unsigned char)RHS.Data[I] ? -1 : 1;
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000080 }
81 if (Length == RHS.Length)
Benjamin Kramer0043e352010-08-26 14:21:08 +000082 return 0;
Jakob Stoklund Olesen160a3bf2010-05-26 21:47:28 +000083 return Length < RHS.Length ? -1 : 1;
84}
85
Douglas Gregor7e54d5b2009-12-31 04:24:34 +000086// Compute the edit distance between the two given strings.
Michael J. Spencer326990f2010-11-26 04:16:08 +000087unsigned StringRef::edit_distance(llvm::StringRef Other,
Douglas Gregor5ee568a2010-10-19 22:13:48 +000088 bool AllowReplacements,
89 unsigned MaxEditDistance) {
Kaelyn Uhrain01d53ec2012-02-15 22:13:07 +000090 return llvm::ComputeEditDistance(
91 llvm::ArrayRef<char>(data(), size()),
92 llvm::ArrayRef<char>(Other.data(), Other.size()),
93 AllowReplacements, MaxEditDistance);
Douglas Gregor441c8b42009-12-30 17:23:44 +000094}
95
Chris Lattner05a32c82009-09-20 01:22:16 +000096//===----------------------------------------------------------------------===//
Daniel Dunbar589fbb12011-11-06 18:04:43 +000097// String Operations
98//===----------------------------------------------------------------------===//
99
100std::string StringRef::lower() const {
101 std::string Result(size(), char());
102 for (size_type i = 0, e = size(); i != e; ++i) {
103 Result[i] = ascii_tolower(Data[i]);
104 }
105 return Result;
106}
107
108std::string StringRef::upper() const {
109 std::string Result(size(), char());
110 for (size_type i = 0, e = size(); i != e; ++i) {
Benjamin Kramera7b966f2011-11-06 20:36:50 +0000111 Result[i] = ascii_toupper(Data[i]);
Daniel Dunbar589fbb12011-11-06 18:04:43 +0000112 }
113 return Result;
114}
115
116//===----------------------------------------------------------------------===//
Chris Lattner05a32c82009-09-20 01:22:16 +0000117// String Searching
118//===----------------------------------------------------------------------===//
119
120
121/// find - Search for the first string \arg Str in the string.
122///
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000123/// \return - The index of the first occurrence of \arg Str, or npos if not
Chris Lattner05a32c82009-09-20 01:22:16 +0000124/// found.
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000125size_t StringRef::find(StringRef Str, size_t From) const {
Chris Lattner05a32c82009-09-20 01:22:16 +0000126 size_t N = Str.size();
127 if (N > Length)
128 return npos;
Benjamin Kramer6e6a5582011-10-15 10:08:31 +0000129
130 // For short haystacks or unsupported needles fall back to the naive algorithm
131 if (Length < 16 || N > 255 || N == 0) {
132 for (size_t e = Length - N + 1, i = min(From, e); i != e; ++i)
133 if (substr(i, N).equals(Str))
134 return i;
135 return npos;
136 }
137
Benjamin Kramere7a07192011-10-17 20:49:40 +0000138 if (From >= Length)
139 return npos;
140
Benjamin Kramer6e6a5582011-10-15 10:08:31 +0000141 // Build the bad char heuristic table, with uint8_t to reduce cache thrashing.
142 uint8_t BadCharSkip[256];
143 std::memset(BadCharSkip, N, 256);
144 for (unsigned i = 0; i != N-1; ++i)
145 BadCharSkip[(uint8_t)Str[i]] = N-1-i;
146
Benjamin Kramere7a07192011-10-17 20:49:40 +0000147 unsigned Len = Length-From, Pos = From;
Benjamin Kramer6e6a5582011-10-15 10:08:31 +0000148 while (Len >= N) {
149 if (substr(Pos, N).equals(Str)) // See if this is the correct substring.
150 return Pos;
151
152 // Otherwise skip the appropriate number of bytes.
Benjamin Kramere7a07192011-10-17 20:49:40 +0000153 uint8_t Skip = BadCharSkip[(uint8_t)(*this)[Pos+N-1]];
Benjamin Kramer6e6a5582011-10-15 10:08:31 +0000154 Len -= Skip;
155 Pos += Skip;
156 }
157
Chris Lattner05a32c82009-09-20 01:22:16 +0000158 return npos;
159}
160
161/// rfind - Search for the last string \arg Str in the string.
162///
Chris Lattner7a2bdde2011-04-15 05:18:47 +0000163/// \return - The index of the last occurrence of \arg Str, or npos if not
Chris Lattner05a32c82009-09-20 01:22:16 +0000164/// found.
Daniel Dunbar2928c832009-11-06 10:58:06 +0000165size_t StringRef::rfind(StringRef Str) const {
Chris Lattner05a32c82009-09-20 01:22:16 +0000166 size_t N = Str.size();
167 if (N > Length)
168 return npos;
169 for (size_t i = Length - N + 1, e = 0; i != e;) {
170 --i;
171 if (substr(i, N).equals(Str))
172 return i;
173 }
174 return npos;
175}
176
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000177/// find_first_of - Find the first character in the string that is in \arg
178/// Chars, or npos if not found.
179///
Benjamin Kramer250eb002010-08-23 18:16:08 +0000180/// Note: O(size() + Chars.size())
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000181StringRef::size_type StringRef::find_first_of(StringRef Chars,
182 size_t From) const {
Benjamin Kramer250eb002010-08-23 18:16:08 +0000183 std::bitset<1 << CHAR_BIT> CharBits;
184 for (size_type i = 0; i != Chars.size(); ++i)
185 CharBits.set((unsigned char)Chars[i]);
186
Daniel Dunbar58ce7ac2009-11-19 18:53:18 +0000187 for (size_type i = min(From, Length), e = Length; i != e; ++i)
Benjamin Kramer250eb002010-08-23 18:16:08 +0000188 if (CharBits.test((unsigned char)Data[i]))
Chris Lattner05a32c82009-09-20 01:22:16 +0000189 return i;
190 return npos;
191}
192
193/// find_first_not_of - Find the first character in the string that is not
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000194/// \arg C or npos if not found.
195StringRef::size_type StringRef::find_first_not_of(char C, size_t From) const {
Daniel Dunbar58ce7ac2009-11-19 18:53:18 +0000196 for (size_type i = min(From, Length), e = Length; i != e; ++i)
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000197 if (Data[i] != C)
198 return i;
199 return npos;
200}
201
202/// find_first_not_of - Find the first character in the string that is not
203/// in the string \arg Chars, or npos if not found.
204///
Benjamin Kramer250eb002010-08-23 18:16:08 +0000205/// Note: O(size() + Chars.size())
Daniel Dunbar64066bd2009-11-11 00:28:53 +0000206StringRef::size_type StringRef::find_first_not_of(StringRef Chars,
207 size_t From) const {
Benjamin Kramer250eb002010-08-23 18:16:08 +0000208 std::bitset<1 << CHAR_BIT> CharBits;
209 for (size_type i = 0; i != Chars.size(); ++i)
210 CharBits.set((unsigned char)Chars[i]);
211
Daniel Dunbar58ce7ac2009-11-19 18:53:18 +0000212 for (size_type i = min(From, Length), e = Length; i != e; ++i)
Benjamin Kramer250eb002010-08-23 18:16:08 +0000213 if (!CharBits.test((unsigned char)Data[i]))
Chris Lattner05a32c82009-09-20 01:22:16 +0000214 return i;
215 return npos;
216}
217
Michael J. Spencer63c133b2010-11-30 23:27:35 +0000218/// find_last_of - Find the last character in the string that is in \arg C,
219/// or npos if not found.
220///
221/// Note: O(size() + Chars.size())
222StringRef::size_type StringRef::find_last_of(StringRef Chars,
223 size_t From) const {
224 std::bitset<1 << CHAR_BIT> CharBits;
225 for (size_type i = 0; i != Chars.size(); ++i)
226 CharBits.set((unsigned char)Chars[i]);
227
228 for (size_type i = min(From, Length) - 1, e = -1; i != e; --i)
229 if (CharBits.test((unsigned char)Data[i]))
230 return i;
231 return npos;
232}
Chris Lattner05a32c82009-09-20 01:22:16 +0000233
Michael J. Spencerb0940b42012-05-11 22:08:50 +0000234/// find_last_not_of - Find the last character in the string that is not
235/// \arg C, or npos if not found.
236StringRef::size_type StringRef::find_last_not_of(char C, size_t From) const {
237 for (size_type i = min(From, Length) - 1, e = -1; i != e; --i)
238 if (Data[i] != C)
239 return i;
240 return npos;
241}
242
243/// find_last_not_of - Find the last character in the string that is not in
244/// \arg Chars, or npos if not found.
245///
246/// Note: O(size() + Chars.size())
247StringRef::size_type StringRef::find_last_not_of(StringRef Chars,
248 size_t From) const {
249 std::bitset<1 << CHAR_BIT> CharBits;
250 for (size_type i = 0, e = Chars.size(); i != e; ++i)
251 CharBits.set((unsigned char)Chars[i]);
252
253 for (size_type i = min(From, Length) - 1, e = -1; i != e; --i)
254 if (!CharBits.test((unsigned char)Data[i]))
255 return i;
256 return npos;
257}
258
Duncan Sandsbf8653f2012-02-21 12:00:25 +0000259void StringRef::split(SmallVectorImpl<StringRef> &A,
260 StringRef Separators, int MaxSplit,
261 bool KeepEmpty) const {
262 StringRef rest = *this;
263
264 // rest.data() is used to distinguish cases like "a," that splits into
265 // "a" + "" and "a" that splits into "a" + 0.
266 for (int splits = 0;
267 rest.data() != NULL && (MaxSplit < 0 || splits < MaxSplit);
268 ++splits) {
269 std::pair<StringRef, StringRef> p = rest.split(Separators);
270
Duncan Sands37b6e5a2012-02-24 09:01:34 +0000271 if (KeepEmpty || p.first.size() != 0)
Duncan Sandsbf8653f2012-02-21 12:00:25 +0000272 A.push_back(p.first);
273 rest = p.second;
274 }
275 // If we have a tail left, add it.
276 if (rest.data() != NULL && (rest.size() != 0 || KeepEmpty))
277 A.push_back(rest);
278}
279
Chris Lattner05a32c82009-09-20 01:22:16 +0000280//===----------------------------------------------------------------------===//
281// Helpful Algorithms
282//===----------------------------------------------------------------------===//
283
284/// count - Return the number of non-overlapped occurrences of \arg Str in
285/// the string.
Daniel Dunbar2928c832009-11-06 10:58:06 +0000286size_t StringRef::count(StringRef Str) const {
Chris Lattner05a32c82009-09-20 01:22:16 +0000287 size_t Count = 0;
288 size_t N = Str.size();
289 if (N > Length)
290 return 0;
291 for (size_t i = 0, e = Length - N + 1; i != e; ++i)
292 if (substr(i, N).equals(Str))
293 ++Count;
294 return Count;
295}
296
John McCall1e7ad392010-02-28 09:55:58 +0000297static unsigned GetAutoSenseRadix(StringRef &Str) {
298 if (Str.startswith("0x")) {
299 Str = Str.substr(2);
300 return 16;
Chris Lattner2dbd7842012-04-21 22:03:05 +0000301 }
302
303 if (Str.startswith("0b")) {
John McCall1e7ad392010-02-28 09:55:58 +0000304 Str = Str.substr(2);
305 return 2;
John McCall1e7ad392010-02-28 09:55:58 +0000306 }
Chris Lattner2dbd7842012-04-21 22:03:05 +0000307
308 if (Str.startswith("0o")) {
309 Str = Str.substr(2);
310 return 8;
311 }
312
313 if (Str.startswith("0"))
314 return 8;
315
316 return 10;
John McCall1e7ad392010-02-28 09:55:58 +0000317}
318
319
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000320/// GetAsUnsignedInteger - Workhorse method that converts a integer character
321/// sequence of radix up to 36 to an unsigned long long value.
Michael J. Spencer9130b422012-03-10 23:02:54 +0000322bool llvm::getAsUnsignedInteger(StringRef Str, unsigned Radix,
323 unsigned long long &Result) {
Chris Lattnercea14382009-09-19 19:47:14 +0000324 // Autosense radix if not specified.
John McCall1e7ad392010-02-28 09:55:58 +0000325 if (Radix == 0)
326 Radix = GetAutoSenseRadix(Str);
Michael J. Spencer326990f2010-11-26 04:16:08 +0000327
Chris Lattnercea14382009-09-19 19:47:14 +0000328 // Empty strings (after the radix autosense) are invalid.
329 if (Str.empty()) return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000330
Chris Lattnercea14382009-09-19 19:47:14 +0000331 // Parse all the bytes of the string given this radix. Watch for overflow.
332 Result = 0;
333 while (!Str.empty()) {
334 unsigned CharVal;
335 if (Str[0] >= '0' && Str[0] <= '9')
336 CharVal = Str[0]-'0';
337 else if (Str[0] >= 'a' && Str[0] <= 'z')
338 CharVal = Str[0]-'a'+10;
339 else if (Str[0] >= 'A' && Str[0] <= 'Z')
340 CharVal = Str[0]-'A'+10;
341 else
342 return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000343
Chris Lattnercea14382009-09-19 19:47:14 +0000344 // If the parsed value is larger than the integer radix, the string is
345 // invalid.
346 if (CharVal >= Radix)
347 return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000348
Chris Lattnercea14382009-09-19 19:47:14 +0000349 // Add in this character.
350 unsigned long long PrevResult = Result;
351 Result = Result*Radix+CharVal;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000352
Nick Kledzik6e033d62012-10-02 20:01:48 +0000353 // Check for overflow by shifting back and seeing if bits were lost.
354 if (Result/Radix < PrevResult)
Chris Lattnercea14382009-09-19 19:47:14 +0000355 return true;
356
357 Str = Str.substr(1);
358 }
Michael J. Spencer326990f2010-11-26 04:16:08 +0000359
Chris Lattnercea14382009-09-19 19:47:14 +0000360 return false;
361}
362
Michael J. Spencer9130b422012-03-10 23:02:54 +0000363bool llvm::getAsSignedInteger(StringRef Str, unsigned Radix,
364 long long &Result) {
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000365 unsigned long long ULLVal;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000366
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000367 // Handle positive strings first.
Michael J. Spencer9130b422012-03-10 23:02:54 +0000368 if (Str.empty() || Str.front() != '-') {
369 if (getAsUnsignedInteger(Str, Radix, ULLVal) ||
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000370 // Check for value so large it overflows a signed value.
371 (long long)ULLVal < 0)
372 return true;
373 Result = ULLVal;
374 return false;
375 }
Michael J. Spencer326990f2010-11-26 04:16:08 +0000376
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000377 // Get the positive part of the value.
Michael J. Spencer9130b422012-03-10 23:02:54 +0000378 if (getAsUnsignedInteger(Str.substr(1), Radix, ULLVal) ||
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000379 // Reject values so large they'd overflow as negative signed, but allow
380 // "-0". This negates the unsigned so that the negative isn't undefined
381 // on signed overflow.
382 (long long)-ULLVal > 0)
383 return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000384
Chris Lattner63c6b7d2009-09-19 23:58:48 +0000385 Result = -ULLVal;
386 return false;
387}
388
John McCall1e7ad392010-02-28 09:55:58 +0000389bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
390 StringRef Str = *this;
391
392 // Autosense radix if not specified.
393 if (Radix == 0)
394 Radix = GetAutoSenseRadix(Str);
395
396 assert(Radix > 1 && Radix <= 36);
Michael J. Spencer326990f2010-11-26 04:16:08 +0000397
John McCall1e7ad392010-02-28 09:55:58 +0000398 // Empty strings (after the radix autosense) are invalid.
399 if (Str.empty()) return true;
400
401 // Skip leading zeroes. This can be a significant improvement if
402 // it means we don't need > 64 bits.
403 while (!Str.empty() && Str.front() == '0')
404 Str = Str.substr(1);
405
406 // If it was nothing but zeroes....
407 if (Str.empty()) {
408 Result = APInt(64, 0);
409 return false;
410 }
411
412 // (Over-)estimate the required number of bits.
413 unsigned Log2Radix = 0;
414 while ((1U << Log2Radix) < Radix) Log2Radix++;
415 bool IsPowerOf2Radix = ((1U << Log2Radix) == Radix);
416
417 unsigned BitWidth = Log2Radix * Str.size();
418 if (BitWidth < Result.getBitWidth())
419 BitWidth = Result.getBitWidth(); // don't shrink the result
Chris Lattnera9963c62012-04-23 00:27:54 +0000420 else if (BitWidth > Result.getBitWidth())
Jay Foad40f8f622010-12-07 08:25:19 +0000421 Result = Result.zext(BitWidth);
John McCall1e7ad392010-02-28 09:55:58 +0000422
423 APInt RadixAP, CharAP; // unused unless !IsPowerOf2Radix
424 if (!IsPowerOf2Radix) {
425 // These must have the same bit-width as Result.
426 RadixAP = APInt(BitWidth, Radix);
427 CharAP = APInt(BitWidth, 0);
428 }
429
430 // Parse all the bytes of the string given this radix.
431 Result = 0;
432 while (!Str.empty()) {
433 unsigned CharVal;
434 if (Str[0] >= '0' && Str[0] <= '9')
435 CharVal = Str[0]-'0';
436 else if (Str[0] >= 'a' && Str[0] <= 'z')
437 CharVal = Str[0]-'a'+10;
438 else if (Str[0] >= 'A' && Str[0] <= 'Z')
439 CharVal = Str[0]-'A'+10;
440 else
441 return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000442
John McCall1e7ad392010-02-28 09:55:58 +0000443 // If the parsed value is larger than the integer radix, the string is
444 // invalid.
445 if (CharVal >= Radix)
446 return true;
Michael J. Spencer326990f2010-11-26 04:16:08 +0000447
John McCall1e7ad392010-02-28 09:55:58 +0000448 // Add in this character.
449 if (IsPowerOf2Radix) {
450 Result <<= Log2Radix;
451 Result |= CharVal;
452 } else {
453 Result *= RadixAP;
454 CharAP = CharVal;
455 Result += CharAP;
456 }
457
458 Str = Str.substr(1);
459 }
Michael J. Spencer326990f2010-11-26 04:16:08 +0000460
John McCall1e7ad392010-02-28 09:55:58 +0000461 return false;
462}
Chandler Carruth528f0bb2012-03-04 10:55:27 +0000463
464
465// Implementation of StringRef hashing.
466hash_code llvm::hash_value(StringRef S) {
467 return hash_combine_range(S.begin(), S.end());
468}