James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2 | From: PJ Reiniger <pj.reiniger@gmail.com> |
| 3 | Date: Sat, 7 May 2022 22:09:18 -0400 |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 4 | Subject: [PATCH 01/31] Remove StringRef, ArrayRef, and Optional |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 5 | |
| 6 | --- |
| 7 | llvm/include/llvm/ADT/PointerUnion.h | 1 - |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 8 | llvm/include/llvm/ADT/SmallSet.h | 2 +- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 9 | llvm/include/llvm/ADT/SmallString.h | 77 ++++++++++--------- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 10 | llvm/include/llvm/ADT/SmallVector.h | 7 +- |
| 11 | llvm/include/llvm/ADT/StringMap.h | 38 ++++----- |
| 12 | llvm/include/llvm/ADT/StringMapEntry.h | 20 ++--- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 13 | llvm/include/llvm/Support/Chrono.h | 10 +-- |
| 14 | llvm/include/llvm/Support/Compiler.h | 2 +- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 15 | llvm/include/llvm/Support/ConvertUTF.h | 31 ++++---- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 16 | llvm/include/llvm/Support/ErrorHandling.h | 9 +-- |
| 17 | .../llvm/Support/SmallVectorMemoryBuffer.h | 6 +- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 18 | llvm/include/llvm/Support/VersionTuple.h | 6 -- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 19 | .../llvm/Support/Windows/WindowsSupport.h | 4 +- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 20 | llvm/include/llvm/Support/raw_ostream.h | 46 ++++++----- |
| 21 | llvm/include/llvm/Support/xxhash.h | 16 ++-- |
| 22 | llvm/lib/Support/ConvertUTFWrapper.cpp | 38 ++++----- |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 23 | llvm/lib/Support/ErrorHandling.cpp | 13 ++-- |
| 24 | llvm/lib/Support/SmallVector.cpp | 5 +- |
| 25 | llvm/lib/Support/StringMap.cpp | 12 +-- |
| 26 | llvm/lib/Support/raw_ostream.cpp | 25 +++--- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 27 | llvm/lib/Support/xxhash.cpp | 10 +-- |
| 28 | llvm/unittests/ADT/DenseMapTest.cpp | 29 +------ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 29 | llvm/unittests/ADT/FunctionExtrasTest.cpp | 12 +-- |
| 30 | llvm/unittests/ADT/HashingTest.cpp | 2 +- |
| 31 | llvm/unittests/ADT/SmallPtrSetTest.cpp | 1 - |
| 32 | llvm/unittests/ADT/SmallStringTest.cpp | 50 ++++++------ |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 33 | llvm/unittests/ADT/SmallVectorTest.cpp | 30 ++------ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 34 | llvm/unittests/ADT/StringMapTest.cpp | 32 ++++---- |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 35 | llvm/unittests/Support/ConvertUTFTest.cpp | 41 +++++----- |
| 36 | llvm/unittests/Support/xxhashTest.cpp | 4 +- |
| 37 | 30 files changed, 264 insertions(+), 315 deletions(-) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 38 | |
| 39 | diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 40 | index 7d4ed02b622626bb8043acb57b8ce7ed97a5f949..8ac68dbc0a791b8ac0e0ca865e69024cb642aa70 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 41 | --- a/llvm/include/llvm/ADT/PointerUnion.h |
| 42 | +++ b/llvm/include/llvm/ADT/PointerUnion.h |
| 43 | @@ -17,7 +17,6 @@ |
| 44 | |
| 45 | #include "llvm/ADT/DenseMapInfo.h" |
| 46 | #include "llvm/ADT/PointerIntPair.h" |
| 47 | -#include "llvm/ADT/STLExtras.h" |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 48 | #include "llvm/Support/Casting.h" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 49 | #include "llvm/Support/PointerLikeTypeTraits.h" |
| 50 | #include <algorithm> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 51 | diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 52 | index a16e8ac6f07552d98250e808190b00ee270f12b3..aeee5f97799aea7e7588d7afba1e47b4fa3d8c7b 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 53 | --- a/llvm/include/llvm/ADT/SmallSet.h |
| 54 | +++ b/llvm/include/llvm/ADT/SmallSet.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 55 | @@ -16,12 +16,12 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 56 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 57 | #include "llvm/ADT/SmallPtrSet.h" |
| 58 | #include "llvm/ADT/SmallVector.h" |
| 59 | -#include "llvm/ADT/STLExtras.h" |
| 60 | #include "llvm/ADT/iterator.h" |
| 61 | #include "llvm/Support/Compiler.h" |
| 62 | #include "llvm/Support/type_traits.h" |
| 63 | #include <cstddef> |
| 64 | #include <functional> |
| 65 | +#include <optional> |
| 66 | #include <set> |
| 67 | #include <type_traits> |
| 68 | #include <utility> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 69 | diff --git a/llvm/include/llvm/ADT/SmallString.h b/llvm/include/llvm/ADT/SmallString.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 70 | index 0052c86fb37b82dcdf577a7acf06e3a47f54da61..4d673cc8b1c49cf8a3f19653de53881cd12662ee 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 71 | --- a/llvm/include/llvm/ADT/SmallString.h |
| 72 | +++ b/llvm/include/llvm/ADT/SmallString.h |
| 73 | @@ -15,8 +15,9 @@ |
| 74 | #define LLVM_ADT_SMALLSTRING_H |
| 75 | |
| 76 | #include "llvm/ADT/SmallVector.h" |
| 77 | -#include "llvm/ADT/StringRef.h" |
| 78 | #include <cstddef> |
| 79 | +#include <string> |
| 80 | +#include <string_view> |
| 81 | |
| 82 | namespace llvm { |
| 83 | |
| 84 | @@ -28,11 +29,11 @@ public: |
| 85 | /// Default ctor - Initialize to empty. |
| 86 | SmallString() = default; |
| 87 | |
| 88 | - /// Initialize from a StringRef. |
| 89 | - SmallString(StringRef S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {} |
| 90 | + /// Initialize from a std::string_view. |
| 91 | + SmallString(std::string_view S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {} |
| 92 | |
| 93 | - /// Initialize by concatenating a list of StringRefs. |
| 94 | - SmallString(std::initializer_list<StringRef> Refs) |
| 95 | + /// Initialize by concatenating a list of std::string_views. |
| 96 | + SmallString(std::initializer_list<std::string_view> Refs) |
| 97 | : SmallVector<char, InternalLen>() { |
| 98 | this->append(Refs); |
| 99 | } |
| 100 | @@ -47,13 +48,13 @@ public: |
| 101 | |
| 102 | using SmallVector<char, InternalLen>::assign; |
| 103 | |
| 104 | - /// Assign from a StringRef. |
| 105 | - void assign(StringRef RHS) { |
| 106 | + /// Assign from a std::string_view. |
| 107 | + void assign(std::string_view RHS) { |
| 108 | SmallVectorImpl<char>::assign(RHS.begin(), RHS.end()); |
| 109 | } |
| 110 | |
| 111 | - /// Assign from a list of StringRefs. |
| 112 | - void assign(std::initializer_list<StringRef> Refs) { |
| 113 | + /// Assign from a list of std::string_views. |
| 114 | + void assign(std::initializer_list<std::string_view> Refs) { |
| 115 | this->clear(); |
| 116 | append(Refs); |
| 117 | } |
| 118 | @@ -64,19 +65,19 @@ public: |
| 119 | |
| 120 | using SmallVector<char, InternalLen>::append; |
| 121 | |
| 122 | - /// Append from a StringRef. |
| 123 | - void append(StringRef RHS) { |
| 124 | + /// Append from a std::string_view. |
| 125 | + void append(std::string_view RHS) { |
| 126 | SmallVectorImpl<char>::append(RHS.begin(), RHS.end()); |
| 127 | } |
| 128 | |
| 129 | - /// Append from a list of StringRefs. |
| 130 | - void append(std::initializer_list<StringRef> Refs) { |
| 131 | + /// Append from a list of std::string_views. |
| 132 | + void append(std::initializer_list<std::string_view> Refs) { |
| 133 | size_t CurrentSize = this->size(); |
| 134 | size_t SizeNeeded = CurrentSize; |
| 135 | - for (const StringRef &Ref : Refs) |
| 136 | + for (const std::string_view &Ref : Refs) |
| 137 | SizeNeeded += Ref.size(); |
| 138 | this->resize_for_overwrite(SizeNeeded); |
| 139 | - for (const StringRef &Ref : Refs) { |
| 140 | + for (const std::string_view &Ref : Refs) { |
| 141 | std::copy(Ref.begin(), Ref.end(), this->begin() + CurrentSize); |
| 142 | CurrentSize += Ref.size(); |
| 143 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 144 | @@ -89,30 +90,30 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 145 | |
| 146 | /// Check for string equality. This is more efficient than compare() when |
| 147 | /// the relative ordering of inequal strings isn't needed. |
| 148 | - bool equals(StringRef RHS) const { |
| 149 | + bool equals(std::string_view RHS) const { |
| 150 | return str().equals(RHS); |
| 151 | } |
| 152 | |
| 153 | /// Check for string equality, ignoring case. |
| 154 | - bool equals_insensitive(StringRef RHS) const { |
| 155 | + bool equals_insensitive(std::string_view RHS) const { |
| 156 | return str().equals_insensitive(RHS); |
| 157 | } |
| 158 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 159 | /// compare - Compare two strings; the result is negative, zero, or positive |
| 160 | /// if this string is lexicographically less than, equal to, or greater than |
| 161 | /// the \p RHS. |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 162 | - int compare(StringRef RHS) const { |
| 163 | + int compare(std::string_view RHS) const { |
| 164 | return str().compare(RHS); |
| 165 | } |
| 166 | |
| 167 | /// compare_insensitive - Compare two strings, ignoring case. |
| 168 | - int compare_insensitive(StringRef RHS) const { |
| 169 | + int compare_insensitive(std::string_view RHS) const { |
| 170 | return str().compare_insensitive(RHS); |
| 171 | } |
| 172 | |
| 173 | /// compare_numeric - Compare two strings, treating sequences of digits as |
| 174 | /// numbers. |
| 175 | - int compare_numeric(StringRef RHS) const { |
| 176 | + int compare_numeric(std::string_view RHS) const { |
| 177 | return str().compare_numeric(RHS); |
| 178 | } |
| 179 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 180 | @@ -121,12 +122,12 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 181 | /// @{ |
| 182 | |
| 183 | /// startswith - Check if this string starts with the given \p Prefix. |
| 184 | - bool startswith(StringRef Prefix) const { |
| 185 | + bool startswith(std::string_view Prefix) const { |
| 186 | return str().startswith(Prefix); |
| 187 | } |
| 188 | |
| 189 | /// endswith - Check if this string ends with the given \p Suffix. |
| 190 | - bool endswith(StringRef Suffix) const { |
| 191 | + bool endswith(std::string_view Suffix) const { |
| 192 | return str().endswith(Suffix); |
| 193 | } |
| 194 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 195 | @@ -146,7 +147,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 196 | /// |
| 197 | /// \returns The index of the first occurrence of \p Str, or npos if not |
| 198 | /// found. |
| 199 | - size_t find(StringRef Str, size_t From = 0) const { |
| 200 | + size_t find(std::string_view Str, size_t From = 0) const { |
| 201 | return str().find(Str, From); |
| 202 | } |
| 203 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 204 | @@ -154,7 +155,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 205 | /// |
| 206 | /// \returns The index of the last occurrence of \p C, or npos if not |
| 207 | /// found. |
| 208 | - size_t rfind(char C, size_t From = StringRef::npos) const { |
| 209 | + size_t rfind(char C, size_t From = std::string_view::npos) const { |
| 210 | return str().rfind(C, From); |
| 211 | } |
| 212 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 213 | @@ -162,7 +163,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 214 | /// |
| 215 | /// \returns The index of the last occurrence of \p Str, or npos if not |
| 216 | /// found. |
| 217 | - size_t rfind(StringRef Str) const { |
| 218 | + size_t rfind(std::string_view Str) const { |
| 219 | return str().rfind(Str); |
| 220 | } |
| 221 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 222 | @@ -176,7 +177,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 223 | /// not found. |
| 224 | /// |
| 225 | /// Complexity: O(size() + Chars.size()) |
| 226 | - size_t find_first_of(StringRef Chars, size_t From = 0) const { |
| 227 | + size_t find_first_of(std::string_view Chars, size_t From = 0) const { |
| 228 | return str().find_first_of(Chars, From); |
| 229 | } |
| 230 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 231 | @@ -190,13 +191,13 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 232 | /// \p Chars, or npos if not found. |
| 233 | /// |
| 234 | /// Complexity: O(size() + Chars.size()) |
| 235 | - size_t find_first_not_of(StringRef Chars, size_t From = 0) const { |
| 236 | + size_t find_first_not_of(std::string_view Chars, size_t From = 0) const { |
| 237 | return str().find_first_not_of(Chars, From); |
| 238 | } |
| 239 | |
| 240 | /// Find the last character in the string that is \p C, or npos if not |
| 241 | /// found. |
| 242 | - size_t find_last_of(char C, size_t From = StringRef::npos) const { |
| 243 | + size_t find_last_of(char C, size_t From = std::string_view::npos) const { |
| 244 | return str().find_last_of(C, From); |
| 245 | } |
| 246 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 247 | @@ -205,7 +206,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 248 | /// |
| 249 | /// Complexity: O(size() + Chars.size()) |
| 250 | size_t find_last_of( |
| 251 | - StringRef Chars, size_t From = StringRef::npos) const { |
| 252 | + std::string_view Chars, size_t From = std::string_view::npos) const { |
| 253 | return str().find_last_of(Chars, From); |
| 254 | } |
| 255 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 256 | @@ -220,7 +221,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 257 | |
| 258 | /// Return the number of non-overlapped occurrences of \p Str in the |
| 259 | /// string. |
| 260 | - size_t count(StringRef Str) const { |
| 261 | + size_t count(std::string_view Str) const { |
| 262 | return str().count(Str); |
| 263 | } |
| 264 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 265 | @@ -237,7 +238,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 266 | /// \param N The number of characters to included in the substring. If \p N |
| 267 | /// exceeds the number of characters remaining in the string, the string |
| 268 | /// suffix (starting with \p Start) will be returned. |
| 269 | - StringRef substr(size_t Start, size_t N = StringRef::npos) const { |
| 270 | + std::string_view substr(size_t Start, size_t N = std::string_view::npos) const { |
| 271 | return str().substr(Start, N); |
| 272 | } |
| 273 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 274 | @@ -251,14 +252,14 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 275 | /// substring. If this is npos, or less than \p Start, or exceeds the |
| 276 | /// number of characters remaining in the string, the string suffix |
| 277 | /// (starting with \p Start) will be returned. |
| 278 | - StringRef slice(size_t Start, size_t End) const { |
| 279 | + std::string_view slice(size_t Start, size_t End) const { |
| 280 | return str().slice(Start, End); |
| 281 | } |
| 282 | |
| 283 | // Extra methods. |
| 284 | |
| 285 | - /// Explicit conversion to StringRef. |
| 286 | - StringRef str() const { return StringRef(this->data(), this->size()); } |
| 287 | + /// Explicit conversion to std::string_view. |
| 288 | + std::string_view str() const { return std::string_view(this->begin(), this->size()); } |
| 289 | |
| 290 | // TODO: Make this const, if it's safe... |
| 291 | const char* c_str() { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 292 | @@ -267,20 +268,20 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 293 | return this->data(); |
| 294 | } |
| 295 | |
| 296 | - /// Implicit conversion to StringRef. |
| 297 | - operator StringRef() const { return str(); } |
| 298 | + /// Implicit conversion to std::string_view. |
| 299 | + operator std::string_view() const { return str(); } |
| 300 | |
| 301 | explicit operator std::string() const { |
| 302 | return std::string(this->data(), this->size()); |
| 303 | } |
| 304 | |
| 305 | // Extra operators. |
| 306 | - SmallString &operator=(StringRef RHS) { |
| 307 | + SmallString &operator=(std::string_view RHS) { |
| 308 | this->assign(RHS); |
| 309 | return *this; |
| 310 | } |
| 311 | |
| 312 | - SmallString &operator+=(StringRef RHS) { |
| 313 | + SmallString &operator+=(std::string_view RHS) { |
| 314 | this->append(RHS.begin(), RHS.end()); |
| 315 | return *this; |
| 316 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 317 | diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h |
| 318 | index 53a107b1574c6a35c66c7fe3c61deb2ffc84b991..4559864ed231206b098936dae4fc378bfa986371 100644 |
| 319 | --- a/llvm/include/llvm/ADT/SmallVector.h |
| 320 | +++ b/llvm/include/llvm/ADT/SmallVector.h |
| 321 | @@ -27,13 +27,12 @@ |
| 322 | #include <limits> |
| 323 | #include <memory> |
| 324 | #include <new> |
| 325 | +#include <span> |
| 326 | #include <type_traits> |
| 327 | #include <utility> |
| 328 | |
| 329 | namespace llvm { |
| 330 | |
| 331 | -template <typename T> class ArrayRef; |
| 332 | - |
| 333 | template <typename IteratorT> class iterator_range; |
| 334 | |
| 335 | template <class Iterator> |
| 336 | @@ -117,7 +116,7 @@ template <class T, typename = void> struct SmallVectorAlignmentAndSize { |
| 337 | }; |
| 338 | |
| 339 | /// This is the part of SmallVectorTemplateBase which does not depend on whether |
| 340 | -/// the type T is a POD. The extra dummy template argument is used by ArrayRef |
| 341 | +/// the type T is a POD. The extra dummy template argument is used by span |
| 342 | /// to avoid unnecessarily requiring T to be complete. |
| 343 | template <typename T, typename = void> |
| 344 | class SmallVectorTemplateCommon |
| 345 | @@ -1233,7 +1232,7 @@ public: |
| 346 | |
| 347 | template <typename U, |
| 348 | typename = std::enable_if_t<std::is_convertible<U, T>::value>> |
| 349 | - explicit SmallVector(ArrayRef<U> A) : SmallVectorImpl<T>(N) { |
| 350 | + explicit SmallVector(span<const U> A) : SmallVectorImpl<T>(N) { |
| 351 | this->append(A.begin(), A.end()); |
| 352 | } |
| 353 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 354 | diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 355 | index 466f95254d102e98343290b211f317f749d7692b..34dfbf83c681f4e81a9dadd9382ddca6ef8d6c1d 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 356 | --- a/llvm/include/llvm/ADT/StringMap.h |
| 357 | +++ b/llvm/include/llvm/ADT/StringMap.h |
| 358 | @@ -60,12 +60,12 @@ protected: |
| 359 | /// specified bucket will be non-null. Otherwise, it will be null. In either |
| 360 | /// case, the FullHashValue field of the bucket will be set to the hash value |
| 361 | /// of the string. |
| 362 | - unsigned LookupBucketFor(StringRef Key); |
| 363 | + unsigned LookupBucketFor(std::string_view Key); |
| 364 | |
| 365 | /// FindKey - Look up the bucket that contains the specified key. If it exists |
| 366 | /// in the map, return the bucket number of the key. Otherwise return -1. |
| 367 | /// This does not modify the map. |
| 368 | - int FindKey(StringRef Key) const; |
| 369 | + int FindKey(std::string_view Key) const; |
| 370 | |
| 371 | /// RemoveKey - Remove the specified StringMapEntry from the table, but do not |
| 372 | /// delete it. This aborts if the value isn't in the table. |
| 373 | @@ -73,7 +73,7 @@ protected: |
| 374 | |
| 375 | /// RemoveKey - Remove the StringMapEntry for the specified key from the |
| 376 | /// table, returning it. If the key is not in the table, this returns null. |
| 377 | - StringMapEntryBase *RemoveKey(StringRef Key); |
| 378 | + StringMapEntryBase *RemoveKey(std::string_view Key); |
| 379 | |
| 380 | /// Allocate the table with the specified number of buckets and otherwise |
| 381 | /// setup the map as empty. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 382 | @@ -127,7 +127,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 383 | : StringMapImpl(InitialSize, static_cast<unsigned>(sizeof(MapEntryTy))), |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 384 | AllocTy(A) {} |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 385 | |
| 386 | - StringMap(std::initializer_list<std::pair<StringRef, ValueTy>> List) |
| 387 | + StringMap(std::initializer_list<std::pair<std::string_view, ValueTy>> List) |
| 388 | : StringMapImpl(List.size(), static_cast<unsigned>(sizeof(MapEntryTy))) { |
| 389 | insert(List); |
| 390 | } |
| 391 | @@ -215,14 +215,14 @@ public: |
| 392 | StringMapKeyIterator<ValueTy>(end())); |
| 393 | } |
| 394 | |
| 395 | - iterator find(StringRef Key) { |
| 396 | + iterator find(std::string_view Key) { |
| 397 | int Bucket = FindKey(Key); |
| 398 | if (Bucket == -1) |
| 399 | return end(); |
| 400 | return iterator(TheTable + Bucket, true); |
| 401 | } |
| 402 | |
| 403 | - const_iterator find(StringRef Key) const { |
| 404 | + const_iterator find(std::string_view Key) const { |
| 405 | int Bucket = FindKey(Key); |
| 406 | if (Bucket == -1) |
| 407 | return end(); |
| 408 | @@ -231,7 +231,7 @@ public: |
| 409 | |
| 410 | /// lookup - Return the entry for the specified key, or a default |
| 411 | /// constructed value if no such entry exists. |
| 412 | - ValueTy lookup(StringRef Key) const { |
| 413 | + ValueTy lookup(std::string_view Key) const { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 414 | const_iterator Iter = find(Key); |
| 415 | if (Iter != end()) |
| 416 | return Iter->second; |
| 417 | @@ -240,7 +240,7 @@ public: |
| 418 | |
| 419 | /// at - Return the entry for the specified key, or abort if no such |
| 420 | /// entry exists. |
| 421 | - const ValueTy &at(StringRef Val) const { |
| 422 | + const ValueTy &at(std::string_view Val) const { |
| 423 | auto Iter = this->find(std::move(Val)); |
| 424 | assert(Iter != this->end() && "StringMap::at failed due to a missing key"); |
| 425 | return Iter->second; |
| 426 | @@ -248,13 +248,13 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 427 | |
| 428 | /// Lookup the ValueTy for the \p Key, or create a default constructed value |
| 429 | /// if the key is not in the map. |
| 430 | - ValueTy &operator[](StringRef Key) { return try_emplace(Key).first->second; } |
| 431 | + ValueTy &operator[](std::string_view Key) { return try_emplace(Key).first->second; } |
| 432 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 433 | /// contains - Return true if the element is in the map, false otherwise. |
| 434 | - bool contains(StringRef Key) const { return find(Key) != end(); } |
| 435 | + bool contains(std::string_view Key) const { return find(Key) != end(); } |
| 436 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 437 | /// count - Return 1 if the element is in the map, 0 otherwise. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 438 | - size_type count(StringRef Key) const { return contains(Key) ? 1 : 0; } |
| 439 | + size_type count(std::string_view Key) const { return contains(Key) ? 1 : 0; } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 440 | |
| 441 | template <typename InputTy> |
| 442 | size_type count(const StringMapEntry<InputTy> &MapEntry) const { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 443 | @@ -304,7 +304,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 444 | /// isn't already in the map. The bool component of the returned pair is true |
| 445 | /// if and only if the insertion takes place, and the iterator component of |
| 446 | /// the pair points to the element with key equivalent to the key of the pair. |
| 447 | - std::pair<iterator, bool> insert(std::pair<StringRef, ValueTy> KV) { |
| 448 | + std::pair<iterator, bool> insert(std::pair<std::string_view, ValueTy> KV) { |
| 449 | return try_emplace(KV.first, std::move(KV.second)); |
| 450 | } |
| 451 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 452 | @@ -319,14 +319,14 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 453 | /// Inserts elements from initializer list ilist. If multiple elements in |
| 454 | /// the range have keys that compare equivalent, it is unspecified which |
| 455 | /// element is inserted |
| 456 | - void insert(std::initializer_list<std::pair<StringRef, ValueTy>> List) { |
| 457 | + void insert(std::initializer_list<std::pair<std::string_view, ValueTy>> List) { |
| 458 | insert(List.begin(), List.end()); |
| 459 | } |
| 460 | |
| 461 | /// Inserts an element or assigns to the current element if the key already |
| 462 | /// exists. The return type is the same as try_emplace. |
| 463 | template <typename V> |
| 464 | - std::pair<iterator, bool> insert_or_assign(StringRef Key, V &&Val) { |
| 465 | + std::pair<iterator, bool> insert_or_assign(std::string_view Key, V &&Val) { |
| 466 | auto Ret = try_emplace(Key, std::forward<V>(Val)); |
| 467 | if (!Ret.second) |
| 468 | Ret.first->second = std::forward<V>(Val); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 469 | @@ -338,7 +338,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 470 | /// if and only if the insertion takes place, and the iterator component of |
| 471 | /// the pair points to the element with key equivalent to the key of the pair. |
| 472 | template <typename... ArgsTy> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 473 | - std::pair<iterator, bool> try_emplace(StringRef Key, ArgsTy &&...Args) { |
| 474 | + std::pair<iterator, bool> try_emplace(std::string_view Key, ArgsTy &&...Args) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 475 | unsigned BucketNo = LookupBucketFor(Key); |
| 476 | StringMapEntryBase *&Bucket = TheTable[BucketNo]; |
| 477 | if (Bucket && Bucket != getTombstoneVal()) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 478 | @@ -385,7 +385,7 @@ public: |
| 479 | V.Destroy(getAllocator()); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | - bool erase(StringRef Key) { |
| 483 | + bool erase(std::string_view Key) { |
| 484 | iterator I = find(Key); |
| 485 | if (I == end()) |
| 486 | return false; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 487 | @@ -482,17 +482,17 @@ template <typename ValueTy> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 488 | class StringMapKeyIterator |
| 489 | : public iterator_adaptor_base<StringMapKeyIterator<ValueTy>, |
| 490 | StringMapConstIterator<ValueTy>, |
| 491 | - std::forward_iterator_tag, StringRef> { |
| 492 | + std::forward_iterator_tag, std::string_view> { |
| 493 | using base = iterator_adaptor_base<StringMapKeyIterator<ValueTy>, |
| 494 | StringMapConstIterator<ValueTy>, |
| 495 | - std::forward_iterator_tag, StringRef>; |
| 496 | + std::forward_iterator_tag, std::string_view>; |
| 497 | |
| 498 | public: |
| 499 | StringMapKeyIterator() = default; |
| 500 | explicit StringMapKeyIterator(StringMapConstIterator<ValueTy> Iter) |
| 501 | : base(std::move(Iter)) {} |
| 502 | |
| 503 | - StringRef operator*() const { return this->wrapped()->getKey(); } |
| 504 | + std::string_view operator*() const { return this->wrapped()->getKey(); } |
| 505 | }; |
| 506 | |
| 507 | } // end namespace llvm |
| 508 | diff --git a/llvm/include/llvm/ADT/StringMapEntry.h b/llvm/include/llvm/ADT/StringMapEntry.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 509 | index 98b51cc1aebd59eba20076e6d8a4eebc0eebb982..388e81c361642113937f7d5680de73a50635b07d 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 510 | --- a/llvm/include/llvm/ADT/StringMapEntry.h |
| 511 | +++ b/llvm/include/llvm/ADT/StringMapEntry.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 512 | @@ -16,8 +16,8 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 513 | #ifndef LLVM_ADT_STRINGMAPENTRY_H |
| 514 | #define LLVM_ADT_STRINGMAPENTRY_H |
| 515 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 516 | -#include "llvm/ADT/StringRef.h" |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 517 | #include <optional> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 518 | +#include <string_view> |
| 519 | |
| 520 | namespace llvm { |
| 521 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 522 | @@ -36,13 +36,13 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 523 | /// type-erase the allocator and put it in a source file. |
| 524 | template <typename AllocatorTy> |
| 525 | static void *allocateWithKey(size_t EntrySize, size_t EntryAlign, |
| 526 | - StringRef Key, AllocatorTy &Allocator); |
| 527 | + std::string_view Key, AllocatorTy &Allocator); |
| 528 | }; |
| 529 | |
| 530 | // Define out-of-line to dissuade inlining. |
| 531 | template <typename AllocatorTy> |
| 532 | void *StringMapEntryBase::allocateWithKey(size_t EntrySize, size_t EntryAlign, |
| 533 | - StringRef Key, |
| 534 | + std::string_view Key, |
| 535 | AllocatorTy &Allocator) { |
| 536 | size_t KeyLength = Key.size(); |
| 537 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 538 | @@ -105,8 +105,8 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 539 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 540 | using ValueType = ValueTy; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 541 | |
| 542 | - StringRef getKey() const { |
| 543 | - return StringRef(getKeyData(), this->getKeyLength()); |
| 544 | + std::string_view getKey() const { |
| 545 | + return std::string_view(getKeyData(), this->getKeyLength()); |
| 546 | } |
| 547 | |
| 548 | /// getKeyData - Return the start of the string data that is the key for this |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 549 | @@ -116,15 +116,15 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 550 | return reinterpret_cast<const char *>(this + 1); |
| 551 | } |
| 552 | |
| 553 | - StringRef first() const { |
| 554 | - return StringRef(getKeyData(), this->getKeyLength()); |
| 555 | + std::string_view first() const { |
| 556 | + return std::string_view(getKeyData(), this->getKeyLength()); |
| 557 | } |
| 558 | |
| 559 | /// Create a StringMapEntry for the specified key construct the value using |
| 560 | /// \p InitiVals. |
| 561 | template <typename AllocatorTy, typename... InitTy> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 562 | - static StringMapEntry *create(StringRef key, AllocatorTy &allocator, |
| 563 | - InitTy &&...initVals) { |
| 564 | + static StringMapEntry *create(std::string_view key, AllocatorTy &allocator, |
| 565 | + InitTy &&... initVals) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 566 | return new (StringMapEntryBase::allocateWithKey( |
| 567 | sizeof(StringMapEntry), alignof(StringMapEntry), key, allocator)) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 568 | StringMapEntry(key.size(), std::forward<InitTy>(initVals)...); |
| 569 | @@ -167,7 +167,7 @@ struct tuple_size<llvm::StringMapEntry<ValueTy>> |
| 570 | |
| 571 | template <std::size_t I, typename ValueTy> |
| 572 | struct tuple_element<I, llvm::StringMapEntry<ValueTy>> |
| 573 | - : std::conditional<I == 0, llvm::StringRef, ValueTy> {}; |
| 574 | + : std::conditional<I == 0, std::string_view, ValueTy> {}; |
| 575 | } // namespace std |
| 576 | |
| 577 | #endif // LLVM_ADT_STRINGMAPENTRY_H |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 578 | diff --git a/llvm/include/llvm/Support/Chrono.h b/llvm/include/llvm/Support/Chrono.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 579 | index 9c2bd45d2803e56ed316d8552d899d87f2fbbb07..a7dea19d9193bcff4bc6b553b80a10b2bc7b64af 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 580 | --- a/llvm/include/llvm/Support/Chrono.h |
| 581 | +++ b/llvm/include/llvm/Support/Chrono.h |
| 582 | @@ -70,7 +70,7 @@ raw_ostream &operator<<(raw_ostream &OS, sys::TimePoint<> TP); |
| 583 | template <> |
| 584 | struct format_provider<sys::TimePoint<>> { |
| 585 | static void format(const sys::TimePoint<> &TP, llvm::raw_ostream &OS, |
| 586 | - StringRef Style); |
| 587 | + std::string_view Style); |
| 588 | }; |
| 589 | |
| 590 | namespace detail { |
| 591 | @@ -122,7 +122,7 @@ private: |
| 592 | return duration_cast<duration<InternalRep, AsPeriod>>(D).count(); |
| 593 | } |
| 594 | |
| 595 | - static std::pair<InternalRep, StringRef> consumeUnit(StringRef &Style, |
| 596 | + static std::pair<InternalRep, std::string_view> consumeUnit(std::string_view &Style, |
| 597 | const Dur &D) { |
| 598 | using namespace std::chrono; |
| 599 | if (Style.consume_front("ns")) |
| 600 | @@ -140,7 +140,7 @@ private: |
| 601 | return {D.count(), detail::unit<Period>::value}; |
| 602 | } |
| 603 | |
| 604 | - static bool consumeShowUnit(StringRef &Style) { |
| 605 | + static bool consumeShowUnit(std::string_view &Style) { |
| 606 | if (Style.empty()) |
| 607 | return true; |
| 608 | if (Style.consume_front("-")) |
| 609 | @@ -152,9 +152,9 @@ private: |
| 610 | } |
| 611 | |
| 612 | public: |
| 613 | - static void format(const Dur &D, llvm::raw_ostream &Stream, StringRef Style) { |
| 614 | + static void format(const Dur &D, llvm::raw_ostream &Stream, std::string_view Style) { |
| 615 | InternalRep count; |
| 616 | - StringRef unit; |
| 617 | + std::string_view unit; |
| 618 | std::tie(count, unit) = consumeUnit(Style, D); |
| 619 | bool show_unit = consumeShowUnit(Style); |
| 620 | |
| 621 | diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 622 | index 10d5cec231a523c943c37a5464cb3943627239a9..92376629c607461061bc60597a47aed1e535af52 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 623 | --- a/llvm/include/llvm/Support/Compiler.h |
| 624 | +++ b/llvm/include/llvm/Support/Compiler.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 625 | @@ -300,7 +300,7 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 626 | #endif |
| 627 | |
| 628 | /// LLVM_GSL_POINTER - Apply this to non-owning classes like |
| 629 | -/// StringRef to enable lifetime warnings. |
| 630 | +/// std::string_view to enable lifetime warnings. |
| 631 | #if LLVM_HAS_CPP_ATTRIBUTE(gsl::Pointer) |
| 632 | #define LLVM_GSL_POINTER [[gsl::Pointer]] |
| 633 | #else |
| 634 | diff --git a/llvm/include/llvm/Support/ConvertUTF.h b/llvm/include/llvm/Support/ConvertUTF.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 635 | index c892bb3c03cb569994429649bdbb96e4118dcef1..5c0e3009c25446a34882fb98329b1d955231bb39 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 636 | --- a/llvm/include/llvm/Support/ConvertUTF.h |
| 637 | +++ b/llvm/include/llvm/Support/ConvertUTF.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 638 | @@ -107,10 +107,9 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 639 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 640 | #include <cstddef> |
| 641 | #include <string> |
| 642 | - |
| 643 | -#if defined(_WIN32) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 644 | +#include <span> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 645 | +#include <string_view> |
| 646 | #include <system_error> |
| 647 | -#endif |
| 648 | |
| 649 | // Wrap everything in namespace llvm so that programs can link with llvm and |
| 650 | // their own version of the unicode libraries. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 651 | @@ -204,12 +203,10 @@ unsigned getNumBytesForUTF8(UTF8 firstByte); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 652 | /*************************************************************************/ |
| 653 | /* Below are LLVM-specific wrappers of the functions above. */ |
| 654 | |
| 655 | -template <typename T> class ArrayRef; |
| 656 | template <typename T> class SmallVectorImpl; |
| 657 | -class StringRef; |
| 658 | |
| 659 | /** |
| 660 | - * Convert an UTF8 StringRef to UTF8, UTF16, or UTF32 depending on |
| 661 | + * Convert an UTF8 string_view to UTF8, UTF16, or UTF32 depending on |
| 662 | * WideCharWidth. The converted data is written to ResultPtr, which needs to |
| 663 | * point to at least WideCharWidth * (Source.Size() + 1) bytes. On success, |
| 664 | * ResultPtr will point one after the end of the copied string. On failure, |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 665 | @@ -217,14 +214,14 @@ class StringRef; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 666 | * the first character which could not be converted. |
| 667 | * \return true on success. |
| 668 | */ |
| 669 | -bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, |
| 670 | +bool ConvertUTF8toWide(unsigned WideCharWidth, std::string_view Source, |
| 671 | char *&ResultPtr, const UTF8 *&ErrorPtr); |
| 672 | |
| 673 | /** |
| 674 | -* Converts a UTF-8 StringRef to a std::wstring. |
| 675 | +* Converts a UTF-8 string_view to a std::wstring. |
| 676 | * \return true on success. |
| 677 | */ |
| 678 | -bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result); |
| 679 | +bool ConvertUTF8toWide(std::string_view Source, std::wstring &Result); |
| 680 | |
| 681 | /** |
| 682 | * Converts a UTF-8 C-string to a std::wstring. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 683 | @@ -282,7 +279,7 @@ inline ConversionResult convertUTF8Sequence(const UTF8 **source, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 684 | * Returns true if a blob of text starts with a UTF-16 big or little endian byte |
| 685 | * order mark. |
| 686 | */ |
| 687 | -bool hasUTF16ByteOrderMark(ArrayRef<char> SrcBytes); |
| 688 | +bool hasUTF16ByteOrderMark(span<const char> SrcBytes); |
| 689 | |
| 690 | /** |
| 691 | * Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 692 | @@ -291,7 +288,7 @@ bool hasUTF16ByteOrderMark(ArrayRef<char> SrcBytes); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 693 | * \param [out] Out Converted UTF-8 is stored here on success. |
| 694 | * \returns true on success |
| 695 | */ |
| 696 | -bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out); |
| 697 | +bool convertUTF16ToUTF8String(span<const char> SrcBytes, std::string &Out); |
| 698 | |
| 699 | /** |
| 700 | * Converts a UTF16 string into a UTF8 std::string. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 701 | @@ -300,7 +297,7 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 702 | * \param [out] Out Converted UTF-8 is stored here on success. |
| 703 | * \returns true on success |
| 704 | */ |
| 705 | -bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out); |
| 706 | +bool convertUTF16ToUTF8String(span<const UTF16> Src, std::string &Out); |
| 707 | |
| 708 | /** |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 709 | * Converts a stream of raw bytes assumed to be UTF32 into a UTF8 std::string. |
| 710 | @@ -309,7 +306,7 @@ bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out); |
| 711 | * \param [out] Out Converted UTF-8 is stored here on success. |
| 712 | * \returns true on success |
| 713 | */ |
| 714 | -bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out); |
| 715 | +bool convertUTF32ToUTF8String(span<const char> SrcBytes, std::string &Out); |
| 716 | |
| 717 | /** |
| 718 | * Converts a UTF32 string into a UTF8 std::string. |
| 719 | @@ -318,22 +315,22 @@ bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out); |
| 720 | * \param [out] Out Converted UTF-8 is stored here on success. |
| 721 | * \returns true on success |
| 722 | */ |
| 723 | -bool convertUTF32ToUTF8String(ArrayRef<UTF32> Src, std::string &Out); |
| 724 | +bool convertUTF32ToUTF8String(span<const UTF32> Src, std::string &Out); |
| 725 | |
| 726 | /** |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 727 | * Converts a UTF-8 string into a UTF-16 string with native endianness. |
| 728 | * |
| 729 | * \returns true on success |
| 730 | */ |
| 731 | -bool convertUTF8ToUTF16String(StringRef SrcUTF8, |
| 732 | +bool convertUTF8ToUTF16String(std::string_view SrcUTF8, |
| 733 | SmallVectorImpl<UTF16> &DstUTF16); |
| 734 | |
| 735 | #if defined(_WIN32) |
| 736 | namespace sys { |
| 737 | namespace windows { |
| 738 | -std::error_code UTF8ToUTF16(StringRef utf8, SmallVectorImpl<wchar_t> &utf16); |
| 739 | +std::error_code UTF8ToUTF16(std::string_view utf8, SmallVectorImpl<wchar_t> &utf16); |
| 740 | /// Convert to UTF16 from the current code page used in the system |
| 741 | -std::error_code CurCPToUTF16(StringRef utf8, SmallVectorImpl<wchar_t> &utf16); |
| 742 | +std::error_code CurCPToUTF16(std::string_view utf8, SmallVectorImpl<wchar_t> &utf16); |
| 743 | std::error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len, |
| 744 | SmallVectorImpl<char> &utf8); |
| 745 | /// Convert from UTF16 to the current code page used in the system |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 746 | diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 747 | index 9c8e3448f3a03e3540adb8b9dd730c77dd9b20ba..68c27a8c67c4f378b92cfa726659ef7824b56dea 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 748 | --- a/llvm/include/llvm/Support/ErrorHandling.h |
| 749 | +++ b/llvm/include/llvm/Support/ErrorHandling.h |
| 750 | @@ -15,10 +15,10 @@ |
| 751 | #define LLVM_SUPPORT_ERRORHANDLING_H |
| 752 | |
| 753 | #include "llvm/Support/Compiler.h" |
| 754 | +#include <string> |
| 755 | +#include <string_view> |
| 756 | |
| 757 | namespace llvm { |
| 758 | - class StringRef; |
| 759 | - class Twine; |
| 760 | |
| 761 | /// An error handler callback. |
| 762 | typedef void (*fatal_error_handler_t)(void *user_data, |
| 763 | @@ -67,12 +67,11 @@ namespace llvm { |
| 764 | /// standard error, followed by a newline. |
| 765 | /// After the error handler is called this function will call abort(), it |
| 766 | /// does not return. |
| 767 | -/// NOTE: The std::string variant was removed to avoid a <string> dependency. |
| 768 | [[noreturn]] void report_fatal_error(const char *reason, |
| 769 | bool gen_crash_diag = true); |
| 770 | -[[noreturn]] void report_fatal_error(StringRef reason, |
| 771 | +[[noreturn]] void report_fatal_error(const std::string &reason, |
| 772 | bool gen_crash_diag = true); |
| 773 | -[[noreturn]] void report_fatal_error(const Twine &reason, |
| 774 | +[[noreturn]] void report_fatal_error(std::string_view reason, |
| 775 | bool gen_crash_diag = true); |
| 776 | |
| 777 | /// Installs a new bad alloc error handler that should be used whenever a |
| 778 | diff --git a/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h b/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 779 | index f7f2d4e54e705d6f29812dc93d1fb0a3ca2dee12..b5e321b5f74ce35940649b9d1342b3cdf0c4931f 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 780 | --- a/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h |
| 781 | +++ b/llvm/include/llvm/Support/SmallVectorMemoryBuffer.h |
| 782 | @@ -35,8 +35,8 @@ public: |
| 783 | RequiresNullTerminator) {} |
| 784 | |
| 785 | /// Construct a named SmallVectorMemoryBuffer from the given SmallVector |
| 786 | - /// r-value and StringRef. |
| 787 | - SmallVectorMemoryBuffer(SmallVectorImpl<char> &&SV, StringRef Name, |
| 788 | + /// r-value and std::string_view. |
| 789 | + SmallVectorMemoryBuffer(SmallVectorImpl<char> &&SV, std::string_view Name, |
| 790 | bool RequiresNullTerminator = true) |
| 791 | : SV(std::move(SV)), BufferName(std::string(Name)) { |
| 792 | if (RequiresNullTerminator) { |
| 793 | @@ -49,7 +49,7 @@ public: |
| 794 | // Key function. |
| 795 | ~SmallVectorMemoryBuffer() override; |
| 796 | |
| 797 | - StringRef getBufferIdentifier() const override { return BufferName; } |
| 798 | + std::string_view getBufferIdentifier() const override { return BufferName; } |
| 799 | |
| 800 | BufferKind getBufferKind() const override { return MemoryBuffer_Malloc; } |
| 801 | |
| 802 | diff --git a/llvm/include/llvm/Support/VersionTuple.h b/llvm/include/llvm/Support/VersionTuple.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 803 | index 828a6db54708dfa9a1a4b4456a92945a92ad80cb..953b40701dc934c1a356b5413c9c6c692d5f5679 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 804 | --- a/llvm/include/llvm/Support/VersionTuple.h |
| 805 | +++ b/llvm/include/llvm/Support/VersionTuple.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 806 | @@ -25,7 +25,6 @@ namespace llvm { |
| 807 | template <typename HasherT, support::endianness Endianness> |
| 808 | class HashBuilderImpl; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 809 | class raw_ostream; |
| 810 | -class StringRef; |
| 811 | |
| 812 | /// Represents a version number in the form major[.minor[.subminor[.build]]]. |
| 813 | class VersionTuple { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 814 | @@ -182,11 +181,6 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 815 | |
| 816 | /// Retrieve a string representation of the version number. |
| 817 | std::string getAsString() const; |
| 818 | - |
| 819 | - /// Try to parse the given string as a version number. |
| 820 | - /// \returns \c true if the string does not match the regular expression |
| 821 | - /// [0-9]+(\.[0-9]+){0,3} |
| 822 | - bool tryParse(StringRef string); |
| 823 | }; |
| 824 | |
| 825 | /// Print a version number. |
| 826 | diff --git a/llvm/include/llvm/Support/Windows/WindowsSupport.h b/llvm/include/llvm/Support/Windows/WindowsSupport.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 827 | index d3aacd14b2097b1e7e13c1003987c1fd52e0cf76..aabdb2f14668a990329b57f5454a0d7db73e12ce 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 828 | --- a/llvm/include/llvm/Support/Windows/WindowsSupport.h |
| 829 | +++ b/llvm/include/llvm/Support/Windows/WindowsSupport.h |
| 830 | @@ -35,8 +35,6 @@ |
| 831 | |
| 832 | #include "llvm/ADT/SmallVector.h" |
| 833 | #include "llvm/ADT/StringExtras.h" |
| 834 | -#include "llvm/ADT/StringRef.h" |
| 835 | -#include "llvm/ADT/Twine.h" |
| 836 | #include "llvm/Config/llvm-config.h" // Get build system configuration settings |
| 837 | #include "llvm/Support/Allocator.h" |
| 838 | #include "llvm/Support/Chrono.h" |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 839 | @@ -74,7 +72,7 @@ bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 840 | [[noreturn]] inline void ReportLastErrorFatal(const char *Msg) { |
| 841 | std::string ErrMsg; |
| 842 | MakeErrMsg(&ErrMsg, Msg); |
| 843 | - llvm::report_fatal_error(Twine(ErrMsg)); |
| 844 | + llvm::report_fatal_error(ErrMsg); |
| 845 | } |
| 846 | |
| 847 | template <typename HandleTraits> |
| 848 | diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 849 | index 1e01eb9ea19c4187302a91457b6d34fbe5b67584..2463f1af612a78cafafe3c0e16d496e607cdc322 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 850 | --- a/llvm/include/llvm/Support/raw_ostream.h |
| 851 | +++ b/llvm/include/llvm/Support/raw_ostream.h |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 852 | @@ -14,13 +14,12 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 853 | #define LLVM_SUPPORT_RAW_OSTREAM_H |
| 854 | |
| 855 | #include "llvm/ADT/SmallVector.h" |
| 856 | -#include "llvm/ADT/StringRef.h" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 857 | -#include "llvm/Support/DataTypes.h" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 858 | #include <cassert> |
| 859 | #include <cstddef> |
| 860 | #include <cstdint> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 861 | #include <cstring> |
| 862 | #include <optional> |
| 863 | +#include <span> |
| 864 | #include <string> |
| 865 | #include <string_view> |
| 866 | #include <system_error> |
| 867 | @@ -208,7 +207,22 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 868 | return *this; |
| 869 | } |
| 870 | |
| 871 | - raw_ostream &operator<<(StringRef Str) { |
| 872 | + raw_ostream &operator<<(span<const uint8_t> Arr) { |
| 873 | + // Inline fast path, particularly for arrays with a known length. |
| 874 | + size_t Size = Arr.size(); |
| 875 | + |
| 876 | + // Make sure we can use the fast path. |
| 877 | + if (Size > (size_t)(OutBufEnd - OutBufCur)) |
| 878 | + return write(Arr.data(), Size); |
| 879 | + |
| 880 | + if (Size) { |
| 881 | + memcpy(OutBufCur, Arr.data(), Size); |
| 882 | + OutBufCur += Size; |
| 883 | + } |
| 884 | + return *this; |
| 885 | + } |
| 886 | + |
| 887 | + raw_ostream &operator<<(std::string_view Str) { |
| 888 | // Inline fast path, particularly for strings with a known length. |
| 889 | size_t Size = Str.size(); |
| 890 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 891 | @@ -241,7 +255,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 892 | // Inline fast path, particularly for constant strings where a sufficiently |
| 893 | // smart compiler will simplify strlen. |
| 894 | |
| 895 | - return this->operator<<(StringRef(Str)); |
| 896 | + return this->operator<<(std::string_view(Str)); |
| 897 | } |
| 898 | |
| 899 | raw_ostream &operator<<(const std::string &Str) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 900 | @@ -249,10 +263,6 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 901 | return write(Str.data(), Str.length()); |
| 902 | } |
| 903 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 904 | - raw_ostream &operator<<(const std::string_view &Str) { |
| 905 | - return write(Str.data(), Str.length()); |
| 906 | - } |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 907 | - |
| 908 | raw_ostream &operator<<(const SmallVectorImpl<char> &Str) { |
| 909 | return write(Str.data(), Str.size()); |
| 910 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 911 | @@ -285,7 +295,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 912 | |
| 913 | /// Output \p Str, turning '\\', '\t', '\n', '"', and anything that doesn't |
| 914 | /// satisfy llvm::isPrint into an escape sequence. |
| 915 | - raw_ostream &write_escaped(StringRef Str, bool UseHexEscapes = false); |
| 916 | + raw_ostream &write_escaped(std::string_view Str, bool UseHexEscapes = false); |
| 917 | |
| 918 | raw_ostream &write(unsigned char C); |
| 919 | raw_ostream &write(const char *Ptr, size_t Size); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 920 | @@ -501,14 +511,14 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 921 | /// As a special case, if Filename is "-", then the stream will use |
| 922 | /// STDOUT_FILENO instead of opening a file. This will not close the stdout |
| 923 | /// descriptor. |
| 924 | - raw_fd_ostream(StringRef Filename, std::error_code &EC); |
| 925 | - raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 926 | + raw_fd_ostream(std::string_view Filename, std::error_code &EC); |
| 927 | + raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 928 | sys::fs::CreationDisposition Disp); |
| 929 | - raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 930 | + raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 931 | sys::fs::FileAccess Access); |
| 932 | - raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 933 | + raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 934 | sys::fs::OpenFlags Flags); |
| 935 | - raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 936 | + raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 937 | sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, |
| 938 | sys::fs::OpenFlags Flags); |
| 939 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 940 | @@ -613,7 +623,7 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 941 | /// Open the specified file for reading/writing/seeking. If an error occurs, |
| 942 | /// information about the error is put into EC, and the stream should be |
| 943 | /// immediately destroyed. |
| 944 | - raw_fd_stream(StringRef Filename, std::error_code &EC); |
| 945 | + raw_fd_stream(std::string_view Filename, std::error_code &EC); |
| 946 | |
| 947 | /// This reads the \p Size bytes into a buffer pointed by \p Ptr. |
| 948 | /// |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 949 | @@ -693,8 +703,8 @@ public: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 950 | |
| 951 | void flush() = delete; |
| 952 | |
| 953 | - /// Return a StringRef for the vector contents. |
| 954 | - StringRef str() const { return StringRef(OS.data(), OS.size()); } |
| 955 | + /// Return a std::string_view for the vector contents. |
| 956 | + std::string_view str() const { return std::string_view(OS.data(), OS.size()); } |
| 957 | |
| 958 | void reserveExtraSpace(uint64_t ExtraSize) override { |
| 959 | OS.reserve(tell() + ExtraSize); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 960 | @@ -751,7 +761,7 @@ class Error; |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 961 | /// for other names. For raw_fd_ostream instances, the stream writes to |
| 962 | /// a temporary file. The final output file is atomically replaced with the |
| 963 | /// temporary file after the \p Write function is finished. |
| 964 | -Error writeToOutput(StringRef OutputFileName, |
| 965 | +Error writeToOutput(std::string_view OutputFileName, |
| 966 | std::function<Error(raw_ostream &)> Write); |
| 967 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 968 | raw_ostream &operator<<(raw_ostream &OS, std::nullopt_t); |
| 969 | diff --git a/llvm/include/llvm/Support/xxhash.h b/llvm/include/llvm/Support/xxhash.h |
| 970 | index 0cef3a54e50d70177a7401324f7a4daca83c6599..3e19ebabb7ad0ff437220d9fdfe59a313386762a 100644 |
| 971 | --- a/llvm/include/llvm/Support/xxhash.h |
| 972 | +++ b/llvm/include/llvm/Support/xxhash.h |
| 973 | @@ -38,16 +38,18 @@ |
| 974 | #ifndef LLVM_SUPPORT_XXHASH_H |
| 975 | #define LLVM_SUPPORT_XXHASH_H |
| 976 | |
| 977 | -#include "llvm/ADT/ArrayRef.h" |
| 978 | -#include "llvm/ADT/StringRef.h" |
| 979 | +#include <stdint.h> |
| 980 | + |
| 981 | +#include <span> |
| 982 | +#include <string_view> |
| 983 | |
| 984 | namespace llvm { |
| 985 | -uint64_t xxHash64(llvm::StringRef Data); |
| 986 | -uint64_t xxHash64(llvm::ArrayRef<uint8_t> Data); |
| 987 | +uint64_t xxHash64(std::string_view Data); |
| 988 | +uint64_t xxHash64(span<const uint8_t> Data); |
| 989 | |
| 990 | -uint64_t xxh3_64bits(ArrayRef<uint8_t> data); |
| 991 | -inline uint64_t xxh3_64bits(StringRef data) { |
| 992 | - return xxh3_64bits(ArrayRef(data.bytes_begin(), data.size())); |
| 993 | +uint64_t xxh3_64bits(span<const uint8_t> data); |
| 994 | +inline uint64_t xxh3_64bits(std::string_view data) { |
| 995 | + return xxh3_64bits(span(reinterpret_cast<const uint8_t*>(data.data()), data.size())); |
| 996 | } |
| 997 | } |
| 998 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 999 | diff --git a/llvm/lib/Support/ConvertUTFWrapper.cpp b/llvm/lib/Support/ConvertUTFWrapper.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1000 | index 3fa7365e72d34a5db941d1cbe2b1beebad5c10e6..d53462e742e61d3476915d5b2c5aa63772e78a8a 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1001 | --- a/llvm/lib/Support/ConvertUTFWrapper.cpp |
| 1002 | +++ b/llvm/lib/Support/ConvertUTFWrapper.cpp |
| 1003 | @@ -6,24 +6,24 @@ |
| 1004 | // |
| 1005 | //===----------------------------------------------------------------------===// |
| 1006 | |
| 1007 | -#include "llvm/ADT/ArrayRef.h" |
| 1008 | -#include "llvm/ADT/StringRef.h" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1009 | #include "llvm/Support/ConvertUTF.h" |
| 1010 | #include "llvm/Support/ErrorHandling.h" |
| 1011 | #include "llvm/Support/SwapByteOrder.h" |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1012 | +#include <span> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1013 | #include <string> |
| 1014 | +#include <string_view> |
| 1015 | #include <vector> |
| 1016 | |
| 1017 | namespace llvm { |
| 1018 | |
| 1019 | -bool ConvertUTF8toWide(unsigned WideCharWidth, llvm::StringRef Source, |
| 1020 | +bool ConvertUTF8toWide(unsigned WideCharWidth, std::string_view Source, |
| 1021 | char *&ResultPtr, const UTF8 *&ErrorPtr) { |
| 1022 | assert(WideCharWidth == 1 || WideCharWidth == 2 || WideCharWidth == 4); |
| 1023 | ConversionResult result = conversionOK; |
| 1024 | // Copy the character span over. |
| 1025 | if (WideCharWidth == 1) { |
| 1026 | - const UTF8 *Pos = reinterpret_cast<const UTF8*>(Source.begin()); |
| 1027 | - if (!isLegalUTF8String(&Pos, reinterpret_cast<const UTF8*>(Source.end()))) { |
| 1028 | + const UTF8 *Pos = reinterpret_cast<const UTF8*>(Source.data()); |
| 1029 | + if (!isLegalUTF8String(&Pos, reinterpret_cast<const UTF8*>(Source.data() + Source.size()))) { |
| 1030 | result = sourceIllegal; |
| 1031 | ErrorPtr = Pos; |
| 1032 | } else { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1033 | @@ -76,12 +76,12 @@ bool ConvertCodePointToUTF8(unsigned Source, char *&ResultPtr) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1034 | return true; |
| 1035 | } |
| 1036 | |
| 1037 | -bool hasUTF16ByteOrderMark(ArrayRef<char> S) { |
| 1038 | +bool hasUTF16ByteOrderMark(span<const char> S) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1039 | return (S.size() >= 2 && ((S[0] == '\xff' && S[1] == '\xfe') || |
| 1040 | (S[0] == '\xfe' && S[1] == '\xff'))); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | -bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) { |
| 1044 | +bool convertUTF16ToUTF8String(span<const char> SrcBytes, std::string &Out) { |
| 1045 | assert(Out.empty()); |
| 1046 | |
| 1047 | // Error out on an uneven byte count. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1048 | @@ -132,14 +132,14 @@ bool convertUTF16ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1049 | return true; |
| 1050 | } |
| 1051 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1052 | -bool convertUTF16ToUTF8String(ArrayRef<UTF16> Src, std::string &Out) { |
| 1053 | +bool convertUTF16ToUTF8String(span<const UTF16> Src, std::string &Out) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1054 | return convertUTF16ToUTF8String( |
| 1055 | - llvm::ArrayRef<char>(reinterpret_cast<const char *>(Src.data()), |
| 1056 | + span<const char>(reinterpret_cast<const char *>(Src.data()), |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1057 | Src.size() * sizeof(UTF16)), |
| 1058 | Out); |
| 1059 | } |
| 1060 | |
| 1061 | -bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) { |
| 1062 | +bool convertUTF32ToUTF8String(span<const char> SrcBytes, std::string &Out) { |
| 1063 | assert(Out.empty()); |
| 1064 | |
| 1065 | // Error out on an uneven byte count. |
| 1066 | @@ -190,14 +190,14 @@ bool convertUTF32ToUTF8String(ArrayRef<char> SrcBytes, std::string &Out) { |
| 1067 | return true; |
| 1068 | } |
| 1069 | |
| 1070 | -bool convertUTF32ToUTF8String(ArrayRef<UTF32> Src, std::string &Out) { |
| 1071 | +bool convertUTF32ToUTF8String(span<const UTF32> Src, std::string &Out) { |
| 1072 | return convertUTF32ToUTF8String( |
| 1073 | - llvm::ArrayRef<char>(reinterpret_cast<const char *>(Src.data()), |
| 1074 | + span<const char>(reinterpret_cast<const char *>(Src.data()), |
| 1075 | Src.size() * sizeof(UTF32)), |
| 1076 | Out); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | -bool convertUTF8ToUTF16String(StringRef SrcUTF8, |
| 1080 | +bool convertUTF8ToUTF16String(std::string_view SrcUTF8, |
| 1081 | SmallVectorImpl<UTF16> &DstUTF16) { |
| 1082 | assert(DstUTF16.empty()); |
| 1083 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1084 | @@ -208,8 +208,8 @@ bool convertUTF8ToUTF16String(StringRef SrcUTF8, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1085 | return true; |
| 1086 | } |
| 1087 | |
| 1088 | - const UTF8 *Src = reinterpret_cast<const UTF8 *>(SrcUTF8.begin()); |
| 1089 | - const UTF8 *SrcEnd = reinterpret_cast<const UTF8 *>(SrcUTF8.end()); |
| 1090 | + const UTF8 *Src = reinterpret_cast<const UTF8 *>(SrcUTF8.data()); |
| 1091 | + const UTF8 *SrcEnd = reinterpret_cast<const UTF8 *>(SrcUTF8.data() + SrcUTF8.size()); |
| 1092 | |
| 1093 | // Allocate the same number of UTF-16 code units as UTF-8 code units. Encoding |
| 1094 | // as UTF-16 should always require the same amount or less code units than the |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1095 | @@ -240,7 +240,7 @@ static_assert(sizeof(wchar_t) == 1 || sizeof(wchar_t) == 2 || |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1096 | "Expected wchar_t to be 1, 2, or 4 bytes"); |
| 1097 | |
| 1098 | template <typename TResult> |
| 1099 | -static inline bool ConvertUTF8toWideInternal(llvm::StringRef Source, |
| 1100 | +static inline bool ConvertUTF8toWideInternal(std::string_view Source, |
| 1101 | TResult &Result) { |
| 1102 | // Even in the case of UTF-16, the number of bytes in a UTF-8 string is |
| 1103 | // at least as large as the number of elements in the resulting wide |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1104 | @@ -256,7 +256,7 @@ static inline bool ConvertUTF8toWideInternal(llvm::StringRef Source, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1105 | return true; |
| 1106 | } |
| 1107 | |
| 1108 | -bool ConvertUTF8toWide(llvm::StringRef Source, std::wstring &Result) { |
| 1109 | +bool ConvertUTF8toWide(std::string_view Source, std::wstring &Result) { |
| 1110 | return ConvertUTF8toWideInternal(Source, Result); |
| 1111 | } |
| 1112 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1113 | @@ -265,7 +265,7 @@ bool ConvertUTF8toWide(const char *Source, std::wstring &Result) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1114 | Result.clear(); |
| 1115 | return true; |
| 1116 | } |
| 1117 | - return ConvertUTF8toWide(llvm::StringRef(Source), Result); |
| 1118 | + return ConvertUTF8toWide(std::string_view(Source), Result); |
| 1119 | } |
| 1120 | |
| 1121 | bool convertWideToUTF8(const std::wstring &Source, std::string &Result) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1122 | @@ -280,7 +280,7 @@ bool convertWideToUTF8(const std::wstring &Source, std::string &Result) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1123 | return true; |
| 1124 | } else if (sizeof(wchar_t) == 2) { |
| 1125 | return convertUTF16ToUTF8String( |
| 1126 | - llvm::ArrayRef<UTF16>(reinterpret_cast<const UTF16 *>(Source.data()), |
| 1127 | + span<const UTF16>(reinterpret_cast<const UTF16 *>(Source.data()), |
| 1128 | Source.size()), |
| 1129 | Result); |
| 1130 | } else if (sizeof(wchar_t) == 4) { |
| 1131 | diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1132 | index b8b3b7424ac6b1de782e739782f9671194ce77a1..0aa13a0f78eb370b2a673ca4a773f26820575052 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1133 | --- a/llvm/lib/Support/ErrorHandling.cpp |
| 1134 | +++ b/llvm/lib/Support/ErrorHandling.cpp |
| 1135 | @@ -14,7 +14,6 @@ |
| 1136 | #include "llvm/Support/ErrorHandling.h" |
| 1137 | #include "llvm-c/ErrorHandling.h" |
| 1138 | #include "llvm/ADT/SmallVector.h" |
| 1139 | -#include "llvm/ADT/Twine.h" |
| 1140 | #include "llvm/Config/config.h" |
| 1141 | #include "llvm/Support/Debug.h" |
| 1142 | #include "llvm/Support/Errc.h" |
| 1143 | @@ -80,14 +79,14 @@ void llvm::remove_fatal_error_handler() { |
| 1144 | } |
| 1145 | |
| 1146 | void llvm::report_fatal_error(const char *Reason, bool GenCrashDiag) { |
| 1147 | - report_fatal_error(Twine(Reason), GenCrashDiag); |
| 1148 | + report_fatal_error(std::string_view(Reason), GenCrashDiag); |
| 1149 | } |
| 1150 | |
| 1151 | -void llvm::report_fatal_error(StringRef Reason, bool GenCrashDiag) { |
| 1152 | - report_fatal_error(Twine(Reason), GenCrashDiag); |
| 1153 | +void llvm::report_fatal_error(const std::string &Reason, bool GenCrashDiag) { |
| 1154 | + report_fatal_error(std::string_view(Reason), GenCrashDiag); |
| 1155 | } |
| 1156 | |
| 1157 | -void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) { |
| 1158 | +void llvm::report_fatal_error(std::string_view Reason, bool GenCrashDiag) { |
| 1159 | llvm::fatal_error_handler_t handler = nullptr; |
| 1160 | void* handlerData = nullptr; |
| 1161 | { |
| 1162 | @@ -101,7 +100,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) { |
| 1163 | } |
| 1164 | |
| 1165 | if (handler) { |
| 1166 | - handler(handlerData, Reason.str().c_str(), GenCrashDiag); |
| 1167 | + handler(handlerData, std::string{Reason}.c_str(), GenCrashDiag); |
| 1168 | } else { |
| 1169 | // Blast the result out to stderr. We don't try hard to make sure this |
| 1170 | // succeeds (e.g. handling EINTR) and we can't use errs() here because |
| 1171 | @@ -109,7 +108,7 @@ void llvm::report_fatal_error(const Twine &Reason, bool GenCrashDiag) { |
| 1172 | SmallVector<char, 64> Buffer; |
| 1173 | raw_svector_ostream OS(Buffer); |
| 1174 | OS << "LLVM ERROR: " << Reason << "\n"; |
| 1175 | - StringRef MessageStr = OS.str(); |
| 1176 | + std::string_view MessageStr = OS.str(); |
| 1177 | ssize_t written = ::write(2, MessageStr.data(), MessageStr.size()); |
| 1178 | (void)written; // If something went wrong, we deliberately just give up. |
| 1179 | } |
| 1180 | diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1181 | index f7e7e80332cc337f6dfa388d1e218e6f3ec95cf2..6cefdff7c28060ca18b522acf5279af3a206e23a 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1182 | --- a/llvm/lib/Support/SmallVector.cpp |
| 1183 | +++ b/llvm/lib/Support/SmallVector.cpp |
| 1184 | @@ -11,7 +11,6 @@ |
| 1185 | //===----------------------------------------------------------------------===// |
| 1186 | |
| 1187 | #include "llvm/ADT/SmallVector.h" |
| 1188 | -#include "llvm/ADT/Twine.h" |
| 1189 | #include "llvm/Support/MemAlloc.h" |
| 1190 | #include <cstdint> |
| 1191 | #ifdef LLVM_ENABLE_EXCEPTIONS |
| 1192 | @@ -67,7 +66,7 @@ static void report_size_overflow(size_t MinSize, size_t MaxSize) { |
| 1193 | #ifdef LLVM_ENABLE_EXCEPTIONS |
| 1194 | throw std::length_error(Reason); |
| 1195 | #else |
| 1196 | - report_fatal_error(Twine(Reason)); |
| 1197 | + report_fatal_error(Reason); |
| 1198 | #endif |
| 1199 | } |
| 1200 | |
| 1201 | @@ -81,7 +80,7 @@ static void report_at_maximum_capacity(size_t MaxSize) { |
| 1202 | #ifdef LLVM_ENABLE_EXCEPTIONS |
| 1203 | throw std::length_error(Reason); |
| 1204 | #else |
| 1205 | - report_fatal_error(Twine(Reason)); |
| 1206 | + report_fatal_error(Reason); |
| 1207 | #endif |
| 1208 | } |
| 1209 | |
| 1210 | diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1211 | index 67c05a87959cf0c243d17646ae2f28f6c9f0d708..7be219323f6d76f32a9a841115f2f146141cdbab 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1212 | --- a/llvm/lib/Support/StringMap.cpp |
| 1213 | +++ b/llvm/lib/Support/StringMap.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1214 | @@ -81,7 +81,7 @@ void StringMapImpl::init(unsigned InitSize) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1215 | /// specified bucket will be non-null. Otherwise, it will be null. In either |
| 1216 | /// case, the FullHashValue field of the bucket will be set to the hash value |
| 1217 | /// of the string. |
| 1218 | -unsigned StringMapImpl::LookupBucketFor(StringRef Name) { |
| 1219 | +unsigned StringMapImpl::LookupBucketFor(std::string_view Name) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1220 | // Hash table unallocated so far? |
| 1221 | if (NumBuckets == 0) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1222 | init(16); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1223 | @@ -121,7 +121,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1224 | // Do the comparison like this because Name isn't necessarily |
| 1225 | // null-terminated! |
| 1226 | char *ItemStr = (char *)BucketItem + ItemSize; |
| 1227 | - if (Name == StringRef(ItemStr, BucketItem->getKeyLength())) { |
| 1228 | + if (Name == std::string_view(ItemStr, BucketItem->getKeyLength())) { |
| 1229 | // We found a match! |
| 1230 | return BucketNo; |
| 1231 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1232 | @@ -139,7 +139,7 @@ unsigned StringMapImpl::LookupBucketFor(StringRef Name) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1233 | /// FindKey - Look up the bucket that contains the specified key. If it exists |
| 1234 | /// in the map, return the bucket number of the key. Otherwise return -1. |
| 1235 | /// This does not modify the map. |
| 1236 | -int StringMapImpl::FindKey(StringRef Key) const { |
| 1237 | +int StringMapImpl::FindKey(std::string_view Key) const { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1238 | if (NumBuckets == 0) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1239 | return -1; // Really empty table? |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1240 | unsigned FullHashValue = xxh3_64bits(Key); |
| 1241 | @@ -166,7 +166,7 @@ int StringMapImpl::FindKey(StringRef Key) const { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1242 | // Do the comparison like this because NameStart isn't necessarily |
| 1243 | // null-terminated! |
| 1244 | char *ItemStr = (char *)BucketItem + ItemSize; |
| 1245 | - if (Key == StringRef(ItemStr, BucketItem->getKeyLength())) { |
| 1246 | + if (Key == std::string_view(ItemStr, BucketItem->getKeyLength())) { |
| 1247 | // We found a match! |
| 1248 | return BucketNo; |
| 1249 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1250 | @@ -185,14 +185,14 @@ int StringMapImpl::FindKey(StringRef Key) const { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1251 | /// delete it. This aborts if the value isn't in the table. |
| 1252 | void StringMapImpl::RemoveKey(StringMapEntryBase *V) { |
| 1253 | const char *VStr = (char *)V + ItemSize; |
| 1254 | - StringMapEntryBase *V2 = RemoveKey(StringRef(VStr, V->getKeyLength())); |
| 1255 | + StringMapEntryBase *V2 = RemoveKey(std::string_view(VStr, V->getKeyLength())); |
| 1256 | (void)V2; |
| 1257 | assert(V == V2 && "Didn't find key?"); |
| 1258 | } |
| 1259 | |
| 1260 | /// RemoveKey - Remove the StringMapEntry for the specified key from the |
| 1261 | /// table, returning it. If the key is not in the table, this returns null. |
| 1262 | -StringMapEntryBase *StringMapImpl::RemoveKey(StringRef Key) { |
| 1263 | +StringMapEntryBase *StringMapImpl::RemoveKey(std::string_view Key) { |
| 1264 | int Bucket = FindKey(Key); |
| 1265 | if (Bucket == -1) |
| 1266 | return nullptr; |
| 1267 | diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1268 | index a4fc605019c211f93dde009e89e7a79b07400aa3..9966a0056ae4f24a7a38346ee1c2f5d83ac20248 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1269 | --- a/llvm/lib/Support/raw_ostream.cpp |
| 1270 | +++ b/llvm/lib/Support/raw_ostream.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1271 | @@ -166,7 +166,7 @@ raw_ostream &raw_ostream::write_uuid(const uuid_t UUID) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | |
| 1275 | -raw_ostream &raw_ostream::write_escaped(StringRef Str, |
| 1276 | +raw_ostream &raw_ostream::write_escaped(std::string_view Str, |
| 1277 | bool UseHexEscapes) { |
| 1278 | for (unsigned char c : Str) { |
| 1279 | switch (c) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1280 | @@ -569,7 +569,7 @@ void format_object_base::home() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1281 | // raw_fd_ostream |
| 1282 | //===----------------------------------------------------------------------===// |
| 1283 | |
| 1284 | -static int getFD(StringRef Filename, std::error_code &EC, |
| 1285 | +static int getFD(std::string_view Filename, std::error_code &EC, |
| 1286 | sys::fs::CreationDisposition Disp, sys::fs::FileAccess Access, |
| 1287 | sys::fs::OpenFlags Flags) { |
| 1288 | assert((Access & sys::fs::FA_Write) && |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1289 | @@ -595,25 +595,25 @@ static int getFD(StringRef Filename, std::error_code &EC, |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1290 | return FD; |
| 1291 | } |
| 1292 | |
| 1293 | -raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC) |
| 1294 | +raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC) |
| 1295 | : raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write, |
| 1296 | sys::fs::OF_None) {} |
| 1297 | |
| 1298 | -raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 1299 | +raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 1300 | sys::fs::CreationDisposition Disp) |
| 1301 | : raw_fd_ostream(Filename, EC, Disp, sys::fs::FA_Write, sys::fs::OF_None) {} |
| 1302 | |
| 1303 | -raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 1304 | +raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 1305 | sys::fs::FileAccess Access) |
| 1306 | : raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, Access, |
| 1307 | sys::fs::OF_None) {} |
| 1308 | |
| 1309 | -raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 1310 | +raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 1311 | sys::fs::OpenFlags Flags) |
| 1312 | : raw_fd_ostream(Filename, EC, sys::fs::CD_CreateAlways, sys::fs::FA_Write, |
| 1313 | Flags) {} |
| 1314 | |
| 1315 | -raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC, |
| 1316 | +raw_fd_ostream::raw_fd_ostream(std::string_view Filename, std::error_code &EC, |
| 1317 | sys::fs::CreationDisposition Disp, |
| 1318 | sys::fs::FileAccess Access, |
| 1319 | sys::fs::OpenFlags Flags) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1320 | @@ -685,8 +685,7 @@ raw_fd_ostream::~raw_fd_ostream() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1321 | // has_error() and clear the error flag with clear_error() before |
| 1322 | // destructing raw_ostream objects which may have errors. |
| 1323 | if (has_error()) |
| 1324 | - report_fatal_error(Twine("IO failure on output stream: ") + |
| 1325 | - error().message(), |
| 1326 | + report_fatal_error("IO failure on output stream: " + error().message(), |
| 1327 | /*gen_crash_diag=*/false); |
| 1328 | } |
| 1329 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1330 | @@ -705,7 +704,7 @@ raw_fd_ostream::~raw_fd_ostream() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1331 | // the input is UTF-8 or transcode from the local codepage to UTF-8 before |
| 1332 | // quoting it. If they don't, this may mess up the encoding, but this is still |
| 1333 | // probably the best compromise we can make. |
| 1334 | -static bool write_console_impl(int FD, StringRef Data) { |
| 1335 | +static bool write_console_impl(int FD, std::string_view Data) { |
| 1336 | SmallVector<wchar_t, 256> WideText; |
| 1337 | |
| 1338 | // Fall back to ::write if it wasn't valid UTF-8. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1339 | @@ -748,7 +747,7 @@ void raw_fd_ostream::write_impl(const char *Ptr, size_t Size) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1340 | // If this is a Windows console device, try re-encoding from UTF-8 to UTF-16 |
| 1341 | // and using WriteConsoleW. If that fails, fall back to plain write(). |
| 1342 | if (IsWindowsConsole) |
| 1343 | - if (write_console_impl(FD, StringRef(Ptr, Size))) |
| 1344 | + if (write_console_impl(FD, std::string_view(Ptr, Size))) |
| 1345 | return; |
| 1346 | #endif |
| 1347 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1348 | @@ -919,7 +918,7 @@ raw_ostream &llvm::nulls() { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1349 | // File Streams |
| 1350 | //===----------------------------------------------------------------------===// |
| 1351 | |
| 1352 | -raw_fd_stream::raw_fd_stream(StringRef Filename, std::error_code &EC) |
| 1353 | +raw_fd_stream::raw_fd_stream(std::string_view Filename, std::error_code &EC) |
| 1354 | : raw_fd_ostream(getFD(Filename, EC, sys::fs::CD_CreateAlways, |
| 1355 | sys::fs::FA_Write | sys::fs::FA_Read, |
| 1356 | sys::fs::OF_None), |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1357 | @@ -997,7 +996,7 @@ void buffer_ostream::anchor() {} |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1358 | |
| 1359 | void buffer_unique_ostream::anchor() {} |
| 1360 | |
| 1361 | -Error llvm::writeToOutput(StringRef OutputFileName, |
| 1362 | +Error llvm::writeToOutput(std::string_view OutputFileName, |
| 1363 | std::function<Error(raw_ostream &)> Write) { |
| 1364 | if (OutputFileName == "-") |
| 1365 | return Write(outs()); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1366 | diff --git a/llvm/lib/Support/xxhash.cpp b/llvm/lib/Support/xxhash.cpp |
| 1367 | index 577f14189caff7d74377f7b28d8332deef4c62c4..b9c15e885a1751eaca43317323bd7a85fa201073 100644 |
| 1368 | --- a/llvm/lib/Support/xxhash.cpp |
| 1369 | +++ b/llvm/lib/Support/xxhash.cpp |
| 1370 | @@ -84,11 +84,11 @@ static uint64_t XXH64_avalanche(uint64_t hash) { |
| 1371 | return hash; |
| 1372 | } |
| 1373 | |
| 1374 | -uint64_t llvm::xxHash64(StringRef Data) { |
| 1375 | +uint64_t llvm::xxHash64(std::string_view Data) { |
| 1376 | size_t Len = Data.size(); |
| 1377 | uint64_t Seed = 0; |
| 1378 | - const unsigned char *P = Data.bytes_begin(); |
| 1379 | - const unsigned char *const BEnd = Data.bytes_end(); |
| 1380 | + const unsigned char *P = reinterpret_cast<const unsigned char*>(Data.data()); |
| 1381 | + const unsigned char *const BEnd = P + Data.size(); |
| 1382 | uint64_t H64; |
| 1383 | |
| 1384 | if (Len >= 32) { |
| 1385 | @@ -144,7 +144,7 @@ uint64_t llvm::xxHash64(StringRef Data) { |
| 1386 | return XXH64_avalanche(H64); |
| 1387 | } |
| 1388 | |
| 1389 | -uint64_t llvm::xxHash64(ArrayRef<uint8_t> Data) { |
| 1390 | +uint64_t llvm::xxHash64(span<const uint8_t> Data) { |
| 1391 | return xxHash64({(const char *)Data.data(), Data.size()}); |
| 1392 | } |
| 1393 | |
| 1394 | @@ -394,7 +394,7 @@ static uint64_t XXH3_hashLong_64b(const uint8_t *input, size_t len, |
| 1395 | (uint64_t)len * PRIME64_1); |
| 1396 | } |
| 1397 | |
| 1398 | -uint64_t llvm::xxh3_64bits(ArrayRef<uint8_t> data) { |
| 1399 | +uint64_t llvm::xxh3_64bits(span<const uint8_t> data) { |
| 1400 | auto *in = data.data(); |
| 1401 | size_t len = data.size(); |
| 1402 | if (len <= 16) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1403 | diff --git a/llvm/unittests/ADT/DenseMapTest.cpp b/llvm/unittests/ADT/DenseMapTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1404 | index cc3244528f27e2bd7eaa385d8b7f49b2fbb7a3e6..b710ac07461ba58faa99cedeae7f209dc0f5902b 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1405 | --- a/llvm/unittests/ADT/DenseMapTest.cpp |
| 1406 | +++ b/llvm/unittests/ADT/DenseMapTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1407 | @@ -9,11 +9,11 @@ |
| 1408 | #include "llvm/ADT/DenseMap.h" |
| 1409 | #include "llvm/ADT/DenseMapInfo.h" |
| 1410 | #include "llvm/ADT/DenseMapInfoVariant.h" |
| 1411 | -#include "llvm/ADT/StringRef.h" |
| 1412 | #include "gmock/gmock.h" |
| 1413 | #include "gtest/gtest.h" |
| 1414 | #include <map> |
| 1415 | #include <set> |
| 1416 | +#include <string_view> |
| 1417 | #include <utility> |
| 1418 | #include <variant> |
| 1419 | |
| 1420 | @@ -499,31 +499,6 @@ TEST(DenseMapCustomTest, ReserveTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | -// Make sure DenseMap works with StringRef keys. |
| 1425 | -TEST(DenseMapCustomTest, StringRefTest) { |
| 1426 | - DenseMap<StringRef, int> M; |
| 1427 | - |
| 1428 | - M["a"] = 1; |
| 1429 | - M["b"] = 2; |
| 1430 | - M["c"] = 3; |
| 1431 | - |
| 1432 | - EXPECT_EQ(3u, M.size()); |
| 1433 | - EXPECT_EQ(1, M.lookup("a")); |
| 1434 | - EXPECT_EQ(2, M.lookup("b")); |
| 1435 | - EXPECT_EQ(3, M.lookup("c")); |
| 1436 | - |
| 1437 | - EXPECT_EQ(0, M.lookup("q")); |
| 1438 | - |
| 1439 | - // Test the empty string, spelled various ways. |
| 1440 | - EXPECT_EQ(0, M.lookup("")); |
| 1441 | - EXPECT_EQ(0, M.lookup(StringRef())); |
| 1442 | - EXPECT_EQ(0, M.lookup(StringRef("a", 0))); |
| 1443 | - M[""] = 42; |
| 1444 | - EXPECT_EQ(42, M.lookup("")); |
| 1445 | - EXPECT_EQ(42, M.lookup(StringRef())); |
| 1446 | - EXPECT_EQ(42, M.lookup(StringRef("a", 0))); |
| 1447 | -} |
| 1448 | - |
| 1449 | // Key traits that allows lookup with either an unsigned or char* key; |
| 1450 | // In the latter case, "a" == 0, "b" == 1 and so on. |
| 1451 | struct TestDenseMapInfo { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1452 | @@ -761,7 +736,7 @@ TEST(DenseMapCustomTest, VariantSupport) { |
| 1453 | // Test that gTest prints map entries as pairs instead of opaque objects. |
| 1454 | // See third-party/unittest/googletest/internal/custom/gtest-printers.h |
| 1455 | TEST(DenseMapCustomTest, PairPrinting) { |
| 1456 | - DenseMap<int, StringRef> Map = {{1, "one"}, {2, "two"}}; |
| 1457 | + DenseMap<int, std::string_view> Map = {{1, "one"}, {2, "two"}}; |
| 1458 | EXPECT_EQ(R"({ (1, "one"), (2, "two") })", ::testing::PrintToString(Map)); |
| 1459 | } |
| 1460 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1461 | diff --git a/llvm/unittests/ADT/FunctionExtrasTest.cpp b/llvm/unittests/ADT/FunctionExtrasTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1462 | index fc856a976946bf6decda9b6724cac66afc7bdcd6..aff9d61c7f0d48834123b04b74a2e4f7c86a56d8 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1463 | --- a/llvm/unittests/ADT/FunctionExtrasTest.cpp |
| 1464 | +++ b/llvm/unittests/ADT/FunctionExtrasTest.cpp |
| 1465 | @@ -249,23 +249,23 @@ TEST(UniqueFunctionTest, Const) { |
| 1466 | |
| 1467 | // Overloaded call operator correctly resolved. |
| 1468 | struct ChooseCorrectOverload { |
| 1469 | - StringRef operator()() { return "non-const"; } |
| 1470 | - StringRef operator()() const { return "const"; } |
| 1471 | + std::string_view operator()() { return "non-const"; } |
| 1472 | + std::string_view operator()() const { return "const"; } |
| 1473 | }; |
| 1474 | - unique_function<StringRef()> ChooseMutable = ChooseCorrectOverload(); |
| 1475 | + unique_function<std::string_view()> ChooseMutable = ChooseCorrectOverload(); |
| 1476 | ChooseCorrectOverload A; |
| 1477 | EXPECT_EQ("non-const", ChooseMutable()); |
| 1478 | EXPECT_EQ("non-const", A()); |
| 1479 | - unique_function<StringRef() const> ChooseConst = ChooseCorrectOverload(); |
| 1480 | + unique_function<std::string_view() const> ChooseConst = ChooseCorrectOverload(); |
| 1481 | const ChooseCorrectOverload &X = A; |
| 1482 | EXPECT_EQ("const", ChooseConst()); |
| 1483 | EXPECT_EQ("const", X()); |
| 1484 | } |
| 1485 | |
| 1486 | // Test that overloads on unique_functions are resolved as expected. |
| 1487 | -std::string returns(StringRef) { return "not a function"; } |
| 1488 | +std::string returns(std::string_view) { return "not a function"; } |
| 1489 | std::string returns(unique_function<double()> F) { return "number"; } |
| 1490 | -std::string returns(unique_function<StringRef()> F) { return "string"; } |
| 1491 | +std::string returns(unique_function<std::string_view()> F) { return "string"; } |
| 1492 | |
| 1493 | TEST(UniqueFunctionTest, SFINAE) { |
| 1494 | EXPECT_EQ("not a function", returns("boo!")); |
| 1495 | diff --git a/llvm/unittests/ADT/HashingTest.cpp b/llvm/unittests/ADT/HashingTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1496 | index 01a8a962b8e2e33ca8f189c049e9548ced42ec3a..62aff9c3b21eea785ca71c6e290c9c4f3a20ae00 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1497 | --- a/llvm/unittests/ADT/HashingTest.cpp |
| 1498 | +++ b/llvm/unittests/ADT/HashingTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1499 | @@ -295,7 +295,7 @@ TEST(HashingTest, HashCombineRangeGoldenTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1500 | #endif |
| 1501 | }; |
| 1502 | for (unsigned i = 0; i < sizeof(golden_data)/sizeof(*golden_data); ++i) { |
| 1503 | - StringRef str = golden_data[i].s; |
| 1504 | + std::string_view str = golden_data[i].s; |
| 1505 | hash_code hash = hash_combine_range(str.begin(), str.end()); |
| 1506 | #if 0 // Enable this to generate paste-able text for the above structure. |
| 1507 | std::string member_str = "\"" + str.str() + "\","; |
| 1508 | diff --git a/llvm/unittests/ADT/SmallPtrSetTest.cpp b/llvm/unittests/ADT/SmallPtrSetTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1509 | index a97f2617cbf70783f3569709f7ee1bff03baebd2..7ed8670fd31ea2a14e6ba7f59a8ac8e35046890c 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1510 | --- a/llvm/unittests/ADT/SmallPtrSetTest.cpp |
| 1511 | +++ b/llvm/unittests/ADT/SmallPtrSetTest.cpp |
| 1512 | @@ -12,7 +12,6 @@ |
| 1513 | |
| 1514 | #include "llvm/ADT/SmallPtrSet.h" |
| 1515 | #include "llvm/ADT/PointerIntPair.h" |
| 1516 | -#include "llvm/ADT/STLExtras.h" |
| 1517 | #include "llvm/Support/PointerLikeTypeTraits.h" |
| 1518 | #include "gtest/gtest.h" |
| 1519 | |
| 1520 | diff --git a/llvm/unittests/ADT/SmallStringTest.cpp b/llvm/unittests/ADT/SmallStringTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1521 | index 2f4df8afeafa592cb9616bb78feb4964187786f2..6cf14700b34739420cd3dc4ff8a4c16ce162f715 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1522 | --- a/llvm/unittests/ADT/SmallStringTest.cpp |
| 1523 | +++ b/llvm/unittests/ADT/SmallStringTest.cpp |
| 1524 | @@ -50,43 +50,43 @@ TEST_F(SmallStringTest, AssignRepeated) { |
| 1525 | } |
| 1526 | |
| 1527 | TEST_F(SmallStringTest, AssignIterPair) { |
| 1528 | - StringRef abc = "abc"; |
| 1529 | + std::string_view abc = "abc"; |
| 1530 | theString.assign(abc.begin(), abc.end()); |
| 1531 | EXPECT_EQ(3u, theString.size()); |
| 1532 | EXPECT_STREQ("abc", theString.c_str()); |
| 1533 | } |
| 1534 | |
| 1535 | -TEST_F(SmallStringTest, AssignStringRef) { |
| 1536 | - StringRef abc = "abc"; |
| 1537 | +TEST_F(SmallStringTest, AssignStringView) { |
| 1538 | + std::string_view abc = "abc"; |
| 1539 | theString.assign(abc); |
| 1540 | EXPECT_EQ(3u, theString.size()); |
| 1541 | EXPECT_STREQ("abc", theString.c_str()); |
| 1542 | } |
| 1543 | |
| 1544 | TEST_F(SmallStringTest, AssignSmallVector) { |
| 1545 | - StringRef abc = "abc"; |
| 1546 | + std::string_view abc = "abc"; |
| 1547 | SmallVector<char, 10> abcVec(abc.begin(), abc.end()); |
| 1548 | theString.assign(abcVec); |
| 1549 | EXPECT_EQ(3u, theString.size()); |
| 1550 | EXPECT_STREQ("abc", theString.c_str()); |
| 1551 | } |
| 1552 | |
| 1553 | -TEST_F(SmallStringTest, AssignStringRefs) { |
| 1554 | +TEST_F(SmallStringTest, AssignStringViews) { |
| 1555 | theString.assign({"abc", "def", "ghi"}); |
| 1556 | EXPECT_EQ(9u, theString.size()); |
| 1557 | EXPECT_STREQ("abcdefghi", theString.c_str()); |
| 1558 | } |
| 1559 | |
| 1560 | TEST_F(SmallStringTest, AppendIterPair) { |
| 1561 | - StringRef abc = "abc"; |
| 1562 | + std::string_view abc = "abc"; |
| 1563 | theString.append(abc.begin(), abc.end()); |
| 1564 | theString.append(abc.begin(), abc.end()); |
| 1565 | EXPECT_EQ(6u, theString.size()); |
| 1566 | EXPECT_STREQ("abcabc", theString.c_str()); |
| 1567 | } |
| 1568 | |
| 1569 | -TEST_F(SmallStringTest, AppendStringRef) { |
| 1570 | - StringRef abc = "abc"; |
| 1571 | +TEST_F(SmallStringTest, AppendStringView) { |
| 1572 | + std::string_view abc = "abc"; |
| 1573 | theString.append(abc); |
| 1574 | theString.append(abc); |
| 1575 | EXPECT_EQ(6u, theString.size()); |
| 1576 | @@ -94,7 +94,7 @@ TEST_F(SmallStringTest, AppendStringRef) { |
| 1577 | } |
| 1578 | |
| 1579 | TEST_F(SmallStringTest, AppendSmallVector) { |
| 1580 | - StringRef abc = "abc"; |
| 1581 | + std::string_view abc = "abc"; |
| 1582 | SmallVector<char, 10> abcVec(abc.begin(), abc.end()); |
| 1583 | theString.append(abcVec); |
| 1584 | theString.append(abcVec); |
| 1585 | @@ -102,11 +102,11 @@ TEST_F(SmallStringTest, AppendSmallVector) { |
| 1586 | EXPECT_STREQ("abcabc", theString.c_str()); |
| 1587 | } |
| 1588 | |
| 1589 | -TEST_F(SmallStringTest, AppendStringRefs) { |
| 1590 | +TEST_F(SmallStringTest, AppendStringViews) { |
| 1591 | theString.append({"abc", "def", "ghi"}); |
| 1592 | EXPECT_EQ(9u, theString.size()); |
| 1593 | EXPECT_STREQ("abcdefghi", theString.c_str()); |
| 1594 | - StringRef Jkl = "jkl"; |
| 1595 | + std::string_view Jkl = "jkl"; |
| 1596 | std::string Mno = "mno"; |
| 1597 | SmallString<4> Pqr("pqr"); |
| 1598 | const char *Stu = "stu"; |
| 1599 | @@ -115,15 +115,15 @@ TEST_F(SmallStringTest, AppendStringRefs) { |
| 1600 | EXPECT_STREQ("abcdefghijklmnopqrstu", theString.c_str()); |
| 1601 | } |
| 1602 | |
| 1603 | -TEST_F(SmallStringTest, StringRefConversion) { |
| 1604 | - StringRef abc = "abc"; |
| 1605 | +TEST_F(SmallStringTest, StringViewConversion) { |
| 1606 | + std::string_view abc = "abc"; |
| 1607 | theString.assign(abc.begin(), abc.end()); |
| 1608 | - StringRef theStringRef = theString; |
| 1609 | - EXPECT_EQ("abc", theStringRef); |
| 1610 | + std::string_view theStringView = theString; |
| 1611 | + EXPECT_EQ("abc", theStringView); |
| 1612 | } |
| 1613 | |
| 1614 | TEST_F(SmallStringTest, StdStringConversion) { |
| 1615 | - StringRef abc = "abc"; |
| 1616 | + std::string_view abc = "abc"; |
| 1617 | theString.assign(abc.begin(), abc.end()); |
| 1618 | std::string theStdString = std::string(theString); |
| 1619 | EXPECT_EQ("abc", theStdString); |
| 1620 | @@ -149,29 +149,29 @@ TEST_F(SmallStringTest, Slice) { |
| 1621 | TEST_F(SmallStringTest, Find) { |
| 1622 | theString = "hello"; |
| 1623 | EXPECT_EQ(2U, theString.find('l')); |
| 1624 | - EXPECT_EQ(StringRef::npos, theString.find('z')); |
| 1625 | - EXPECT_EQ(StringRef::npos, theString.find("helloworld")); |
| 1626 | + EXPECT_EQ(std::string_view::npos, theString.find('z')); |
| 1627 | + EXPECT_EQ(std::string_view::npos, theString.find("helloworld")); |
| 1628 | EXPECT_EQ(0U, theString.find("hello")); |
| 1629 | EXPECT_EQ(1U, theString.find("ello")); |
| 1630 | - EXPECT_EQ(StringRef::npos, theString.find("zz")); |
| 1631 | + EXPECT_EQ(std::string_view::npos, theString.find("zz")); |
| 1632 | EXPECT_EQ(2U, theString.find("ll", 2)); |
| 1633 | - EXPECT_EQ(StringRef::npos, theString.find("ll", 3)); |
| 1634 | + EXPECT_EQ(std::string_view::npos, theString.find("ll", 3)); |
| 1635 | EXPECT_EQ(0U, theString.find("")); |
| 1636 | |
| 1637 | EXPECT_EQ(3U, theString.rfind('l')); |
| 1638 | - EXPECT_EQ(StringRef::npos, theString.rfind('z')); |
| 1639 | - EXPECT_EQ(StringRef::npos, theString.rfind("helloworld")); |
| 1640 | + EXPECT_EQ(std::string_view::npos, theString.rfind('z')); |
| 1641 | + EXPECT_EQ(std::string_view::npos, theString.rfind("helloworld")); |
| 1642 | EXPECT_EQ(0U, theString.rfind("hello")); |
| 1643 | EXPECT_EQ(1U, theString.rfind("ello")); |
| 1644 | - EXPECT_EQ(StringRef::npos, theString.rfind("zz")); |
| 1645 | + EXPECT_EQ(std::string_view::npos, theString.rfind("zz")); |
| 1646 | |
| 1647 | EXPECT_EQ(2U, theString.find_first_of('l')); |
| 1648 | EXPECT_EQ(1U, theString.find_first_of("el")); |
| 1649 | - EXPECT_EQ(StringRef::npos, theString.find_first_of("xyz")); |
| 1650 | + EXPECT_EQ(std::string_view::npos, theString.find_first_of("xyz")); |
| 1651 | |
| 1652 | EXPECT_EQ(1U, theString.find_first_not_of('h')); |
| 1653 | EXPECT_EQ(4U, theString.find_first_not_of("hel")); |
| 1654 | - EXPECT_EQ(StringRef::npos, theString.find_first_not_of("hello")); |
| 1655 | + EXPECT_EQ(std::string_view::npos, theString.find_first_not_of("hello")); |
| 1656 | |
| 1657 | theString = "hellx xello hell ello world foo bar hello"; |
| 1658 | EXPECT_EQ(36U, theString.find("hello")); |
| 1659 | diff --git a/llvm/unittests/ADT/SmallVectorTest.cpp b/llvm/unittests/ADT/SmallVectorTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1660 | index 137dd43b473068eae34b39edc4b9b8b9633bab95..7029038d18d433cef987bedbfa4fda269b24fb8f 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1661 | --- a/llvm/unittests/ADT/SmallVectorTest.cpp |
| 1662 | +++ b/llvm/unittests/ADT/SmallVectorTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1663 | @@ -11,10 +11,10 @@ |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1664 | //===----------------------------------------------------------------------===// |
| 1665 | |
| 1666 | #include "llvm/ADT/SmallVector.h" |
| 1667 | -#include "llvm/ADT/ArrayRef.h" |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1668 | #include "llvm/Support/Compiler.h" |
| 1669 | #include "gtest/gtest.h" |
| 1670 | #include <list> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1671 | +#include <span> |
| 1672 | #include <stdarg.h> |
| 1673 | |
| 1674 | using namespace llvm; |
| 1675 | @@ -252,11 +252,11 @@ TYPED_TEST(SmallVectorTest, ConstructorIterTest) { |
| 1676 | } |
| 1677 | |
| 1678 | // Constructor test. |
| 1679 | -TYPED_TEST(SmallVectorTest, ConstructorFromArrayRefSimpleTest) { |
| 1680 | - SCOPED_TRACE("ConstructorFromArrayRefSimpleTest"); |
| 1681 | +TYPED_TEST(SmallVectorTest, ConstructorFromSpanSimpleTest) { |
| 1682 | + SCOPED_TRACE("ConstructorFromSpanSimpleTest"); |
| 1683 | std::array<Constructable, 3> StdArray = {Constructable(1), Constructable(2), |
| 1684 | Constructable(3)}; |
| 1685 | - ArrayRef<Constructable> Array = StdArray; |
| 1686 | + span<const Constructable> Array = StdArray; |
| 1687 | auto &V = this->theVector; |
| 1688 | V = SmallVector<Constructable, 4>(Array); |
| 1689 | assertValuesInOrder(V, 3u, 1, 2, 3); |
| 1690 | @@ -1129,24 +1129,6 @@ TEST(SmallVectorTest, DefaultInlinedElements) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1691 | EXPECT_EQ(NestedV[0][0][0], 42); |
| 1692 | } |
| 1693 | |
| 1694 | -TEST(SmallVectorTest, InitializerList) { |
| 1695 | - SmallVector<int, 2> V1 = {}; |
| 1696 | - EXPECT_TRUE(V1.empty()); |
| 1697 | - V1 = {0, 0}; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1698 | - EXPECT_TRUE(ArrayRef(V1).equals({0, 0})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1699 | - V1 = {-1, -1}; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1700 | - EXPECT_TRUE(ArrayRef(V1).equals({-1, -1})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1701 | - |
| 1702 | - SmallVector<int, 2> V2 = {1, 2, 3, 4}; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1703 | - EXPECT_TRUE(ArrayRef(V2).equals({1, 2, 3, 4})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1704 | - V2.assign({4}); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1705 | - EXPECT_TRUE(ArrayRef(V2).equals({4})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1706 | - V2.append({3, 2}); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1707 | - EXPECT_TRUE(ArrayRef(V2).equals({4, 3, 2})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1708 | - V2.insert(V2.begin() + 1, 5); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1709 | - EXPECT_TRUE(ArrayRef(V2).equals({4, 5, 3, 2})); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1710 | -} |
| 1711 | - |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1712 | TEST(SmallVectorTest, ToVector) { |
| 1713 | { |
| 1714 | std::vector<char> v = {'a', 'b', 'c'}; |
| 1715 | @@ -1183,10 +1165,10 @@ private: |
| 1716 | To T; |
| 1717 | }; |
| 1718 | |
| 1719 | -TEST(SmallVectorTest, ConstructFromArrayRefOfConvertibleType) { |
| 1720 | +TEST(SmallVectorTest, ConstructFromSpanOfConvertibleType) { |
| 1721 | To to1{1}, to2{2}, to3{3}; |
| 1722 | std::vector<From> StdVector = {From(to1), From(to2), From(to3)}; |
| 1723 | - ArrayRef<From> Array = StdVector; |
| 1724 | + span<const From> Array = StdVector; |
| 1725 | { |
| 1726 | llvm::SmallVector<To> Vector(Array); |
| 1727 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1728 | diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1729 | index f9b138e9a472137139397d9cae76823711594211..7f10b3d7d3a8894b1ab0ac660268d94a8b89e082 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1730 | --- a/llvm/unittests/ADT/StringMapTest.cpp |
| 1731 | +++ b/llvm/unittests/ADT/StringMapTest.cpp |
| 1732 | @@ -7,8 +7,6 @@ |
| 1733 | //===----------------------------------------------------------------------===// |
| 1734 | |
| 1735 | #include "llvm/ADT/StringMap.h" |
| 1736 | -#include "llvm/ADT/STLExtras.h" |
| 1737 | -#include "llvm/ADT/Twine.h" |
| 1738 | #include "llvm/Support/DataTypes.h" |
| 1739 | #include "gtest/gtest.h" |
| 1740 | #include <limits> |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1741 | @@ -43,10 +41,10 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1742 | // Lookup tests |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1743 | EXPECT_FALSE(testMap.contains(testKey)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1744 | EXPECT_EQ(0u, testMap.count(testKey)); |
| 1745 | - EXPECT_EQ(0u, testMap.count(StringRef(testKeyFirst, testKeyLength))); |
| 1746 | + EXPECT_EQ(0u, testMap.count(std::string_view(testKeyFirst, testKeyLength))); |
| 1747 | EXPECT_EQ(0u, testMap.count(testKeyStr)); |
| 1748 | EXPECT_TRUE(testMap.find(testKey) == testMap.end()); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1749 | - EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == |
| 1750 | + EXPECT_TRUE(testMap.find(std::string_view(testKeyFirst, testKeyLength)) == |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1751 | testMap.end()); |
| 1752 | EXPECT_TRUE(testMap.find(testKeyStr) == testMap.end()); |
| 1753 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1754 | @@ -67,10 +65,10 @@ protected: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1755 | // Lookup tests |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1756 | EXPECT_TRUE(testMap.contains(testKey)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1757 | EXPECT_EQ(1u, testMap.count(testKey)); |
| 1758 | - EXPECT_EQ(1u, testMap.count(StringRef(testKeyFirst, testKeyLength))); |
| 1759 | + EXPECT_EQ(1u, testMap.count(std::string_view(testKeyFirst, testKeyLength))); |
| 1760 | EXPECT_EQ(1u, testMap.count(testKeyStr)); |
| 1761 | EXPECT_TRUE(testMap.find(testKey) == testMap.begin()); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1762 | - EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == |
| 1763 | + EXPECT_TRUE(testMap.find(std::string_view(testKeyFirst, testKeyLength)) == |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1764 | testMap.begin()); |
| 1765 | EXPECT_TRUE(testMap.find(testKeyStr) == testMap.begin()); |
| 1766 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1767 | @@ -108,10 +106,10 @@ TEST_F(StringMapTest, ConstEmptyMapTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1768 | |
| 1769 | // Lookup tests |
| 1770 | EXPECT_EQ(0u, constTestMap.count(testKey)); |
| 1771 | - EXPECT_EQ(0u, constTestMap.count(StringRef(testKeyFirst, testKeyLength))); |
| 1772 | + EXPECT_EQ(0u, constTestMap.count(std::string_view(testKeyFirst, testKeyLength))); |
| 1773 | EXPECT_EQ(0u, constTestMap.count(testKeyStr)); |
| 1774 | EXPECT_TRUE(constTestMap.find(testKey) == constTestMap.end()); |
| 1775 | - EXPECT_TRUE(constTestMap.find(StringRef(testKeyFirst, testKeyLength)) == |
| 1776 | + EXPECT_TRUE(constTestMap.find(std::string_view(testKeyFirst, testKeyLength)) == |
| 1777 | constTestMap.end()); |
| 1778 | EXPECT_TRUE(constTestMap.find(testKeyStr) == constTestMap.end()); |
| 1779 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1780 | @@ -251,7 +249,7 @@ TEST_F(StringMapTest, StringMapEntryTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1781 | MallocAllocator Allocator; |
| 1782 | StringMap<uint32_t>::value_type *entry = |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1783 | StringMap<uint32_t>::value_type::create( |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1784 | - StringRef(testKeyFirst, testKeyLength), Allocator, 1u); |
| 1785 | + std::string_view(testKeyFirst, testKeyLength), Allocator, 1u); |
| 1786 | EXPECT_STREQ(testKey, entry->first().data()); |
| 1787 | EXPECT_EQ(1u, entry->second); |
| 1788 | entry->Destroy(Allocator); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1789 | @@ -261,7 +259,7 @@ TEST_F(StringMapTest, StringMapEntryTest) { |
| 1790 | TEST_F(StringMapTest, InsertTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1791 | SCOPED_TRACE("InsertTest"); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1792 | testMap.insert(StringMap<uint32_t>::value_type::create( |
| 1793 | - StringRef(testKeyFirst, testKeyLength), testMap.getAllocator(), 1u)); |
| 1794 | + std::string_view(testKeyFirst, testKeyLength), testMap.getAllocator(), 1u)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1795 | assertSingleItemMap(); |
| 1796 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1797 | |
| 1798 | @@ -330,10 +328,10 @@ TEST_F(StringMapTest, IterMapKeysVector) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1799 | Map["C"] = 3; |
| 1800 | Map["D"] = 3; |
| 1801 | |
| 1802 | - std::vector<StringRef> Keys{Map.keys().begin(), Map.keys().end()}; |
| 1803 | + std::vector<std::string_view> Keys{Map.keys().begin(), Map.keys().end()}; |
| 1804 | llvm::sort(Keys); |
| 1805 | |
| 1806 | - std::vector<StringRef> Expected{{"A", "B", "C", "D"}}; |
| 1807 | + std::vector<std::string_view> Expected{{"A", "B", "C", "D"}}; |
| 1808 | EXPECT_EQ(Expected, Keys); |
| 1809 | } |
| 1810 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1811 | @@ -347,7 +345,7 @@ TEST_F(StringMapTest, IterMapKeysSmallVector) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1812 | auto Keys = to_vector<4>(Map.keys()); |
| 1813 | llvm::sort(Keys); |
| 1814 | |
| 1815 | - SmallVector<StringRef, 4> Expected = {"A", "B", "C", "D"}; |
| 1816 | + SmallVector<std::string_view, 4> Expected = {"A", "B", "C", "D"}; |
| 1817 | EXPECT_EQ(Expected, Keys); |
| 1818 | } |
| 1819 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1820 | @@ -389,13 +387,13 @@ private: |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1821 | TEST_F(StringMapTest, MoveOnly) { |
| 1822 | StringMap<MoveOnly> t; |
| 1823 | t.insert(std::make_pair("Test", MoveOnly(42))); |
| 1824 | - StringRef Key = "Test"; |
| 1825 | + std::string_view Key = "Test"; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1826 | StringMapEntry<MoveOnly>::create(Key, t.getAllocator(), MoveOnly(42)) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1827 | ->Destroy(t.getAllocator()); |
| 1828 | } |
| 1829 | |
| 1830 | TEST_F(StringMapTest, CtorArg) { |
| 1831 | - StringRef Key = "Test"; |
| 1832 | + std::string_view Key = "Test"; |
| 1833 | MallocAllocator Allocator; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1834 | StringMapEntry<MoveOnly>::create(Key, Allocator, Immovable()) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1835 | ->Destroy(Allocator); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1836 | @@ -580,7 +578,7 @@ TEST(StringMapCustomTest, InitialSizeTest) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1837 | CountCtorCopyAndMove::Copy = 0; |
| 1838 | for (int i = 0; i < Size; ++i) |
| 1839 | Map.insert(std::pair<std::string, CountCtorCopyAndMove>( |
| 1840 | - std::piecewise_construct, std::forward_as_tuple(Twine(i).str()), |
| 1841 | + std::piecewise_construct, std::forward_as_tuple(std::to_string(i)), |
| 1842 | std::forward_as_tuple(i))); |
| 1843 | // After the initial move, the map will move the Elts in the Entry. |
| 1844 | EXPECT_EQ((unsigned)Size * 2, CountCtorCopyAndMove::Move); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1845 | @@ -649,7 +647,7 @@ TEST(StringMapCustomTest, StringMapEntrySize) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1846 | else |
| 1847 | LargeValue = std::numeric_limits<unsigned>::max() + 1ULL; |
| 1848 | StringMapEntry<int> LargeEntry(LargeValue); |
| 1849 | - StringRef Key = LargeEntry.getKey(); |
| 1850 | + std::string_view Key = LargeEntry.getKey(); |
| 1851 | EXPECT_EQ(LargeValue, Key.size()); |
| 1852 | |
| 1853 | // Test that the entry can hold at least max size_t. |
| 1854 | diff --git a/llvm/unittests/Support/ConvertUTFTest.cpp b/llvm/unittests/Support/ConvertUTFTest.cpp |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1855 | index 6e75fbae0969ba1bf0a76c4d79a123e405a8dae7..3b07d344f15a555f11ad5f8177a0a65b8a4fa472 100644 |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1856 | --- a/llvm/unittests/Support/ConvertUTFTest.cpp |
| 1857 | +++ b/llvm/unittests/Support/ConvertUTFTest.cpp |
| 1858 | @@ -7,7 +7,6 @@ |
| 1859 | //===----------------------------------------------------------------------===// |
| 1860 | |
| 1861 | #include "llvm/Support/ConvertUTF.h" |
| 1862 | -#include "llvm/ADT/ArrayRef.h" |
| 1863 | #include "gtest/gtest.h" |
| 1864 | #include <string> |
| 1865 | #include <vector> |
| 1866 | @@ -17,7 +16,7 @@ using namespace llvm; |
| 1867 | TEST(ConvertUTFTest, ConvertUTF16LittleEndianToUTF8String) { |
| 1868 | // Src is the look of disapproval. |
| 1869 | alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; |
| 1870 | - ArrayRef<char> Ref(Src, sizeof(Src) - 1); |
| 1871 | + span<const char> Ref(Src, sizeof(Src) - 1); |
| 1872 | std::string Result; |
| 1873 | bool Success = convertUTF16ToUTF8String(Ref, Result); |
| 1874 | EXPECT_TRUE(Success); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1875 | @@ -29,7 +28,7 @@ TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) { |
| 1876 | // Src is the look of disapproval. |
| 1877 | alignas(UTF32) static const char Src[] = |
| 1878 | "\xFF\xFE\x00\x00\xA0\x0C\x00\x00\x5F\x00\x00\x00\xA0\x0C\x00\x00"; |
| 1879 | - ArrayRef<char> Ref(Src, sizeof(Src) - 1); |
| 1880 | + span<const char> Ref(Src, sizeof(Src) - 1); |
| 1881 | std::string Result; |
| 1882 | bool Success = convertUTF32ToUTF8String(Ref, Result); |
| 1883 | EXPECT_TRUE(Success); |
| 1884 | @@ -40,7 +39,7 @@ TEST(ConvertUTFTest, ConvertUTF32LittleEndianToUTF8String) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1885 | TEST(ConvertUTFTest, ConvertUTF16BigEndianToUTF8String) { |
| 1886 | // Src is the look of disapproval. |
| 1887 | alignas(UTF16) static const char Src[] = "\xfe\xff\x0c\xa0\x00_\x0c\xa0"; |
| 1888 | - ArrayRef<char> Ref(Src, sizeof(Src) - 1); |
| 1889 | + span<const char> Ref(Src, sizeof(Src) - 1); |
| 1890 | std::string Result; |
| 1891 | bool Success = convertUTF16ToUTF8String(Ref, Result); |
| 1892 | EXPECT_TRUE(Success); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1893 | @@ -52,7 +51,7 @@ TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) { |
| 1894 | // Src is the look of disapproval. |
| 1895 | alignas(UTF32) static const char Src[] = |
| 1896 | "\x00\x00\xFE\xFF\x00\x00\x0C\xA0\x00\x00\x00\x5F\x00\x00\x0C\xA0"; |
| 1897 | - ArrayRef<char> Ref(Src, sizeof(Src) - 1); |
| 1898 | + span<const char> Ref(Src, sizeof(Src) - 1); |
| 1899 | std::string Result; |
| 1900 | bool Success = convertUTF32ToUTF8String(Ref, Result); |
| 1901 | EXPECT_TRUE(Success); |
| 1902 | @@ -63,7 +62,7 @@ TEST(ConvertUTFTest, ConvertUTF32BigEndianToUTF8String) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1903 | TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) { |
| 1904 | // Src is the look of disapproval. |
| 1905 | static const char Src[] = "\xe0\xb2\xa0_\xe0\xb2\xa0"; |
| 1906 | - StringRef Ref(Src, sizeof(Src) - 1); |
| 1907 | + std::string_view Ref(Src, sizeof(Src) - 1); |
| 1908 | SmallVector<UTF16, 5> Result; |
| 1909 | bool Success = convertUTF8ToUTF16String(Ref, Result); |
| 1910 | EXPECT_TRUE(Success); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1911 | @@ -75,38 +74,38 @@ TEST(ConvertUTFTest, ConvertUTF8ToUTF16String) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1912 | |
| 1913 | TEST(ConvertUTFTest, OddLengthInput) { |
| 1914 | std::string Result; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1915 | - bool Success = convertUTF16ToUTF8String(ArrayRef("xxxxx", 5), Result); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1916 | + bool Success = convertUTF16ToUTF8String(span<const char>("xxxxx", 5), Result); |
| 1917 | EXPECT_FALSE(Success); |
| 1918 | } |
| 1919 | |
| 1920 | TEST(ConvertUTFTest, Empty) { |
| 1921 | std::string Result; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1922 | bool Success = |
| 1923 | - convertUTF16ToUTF8String(llvm::ArrayRef<char>(std::nullopt), Result); |
| 1924 | + convertUTF16ToUTF8String(span<const char>(), Result); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1925 | EXPECT_TRUE(Success); |
| 1926 | EXPECT_TRUE(Result.empty()); |
| 1927 | } |
| 1928 | |
| 1929 | TEST(ConvertUTFTest, HasUTF16BOM) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1930 | - bool HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xff\xfe", 2)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1931 | + bool HasBOM = hasUTF16ByteOrderMark("\xff\xfe"); |
| 1932 | EXPECT_TRUE(HasBOM); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1933 | - HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff", 2)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1934 | + HasBOM = hasUTF16ByteOrderMark("\xfe\xff"); |
| 1935 | EXPECT_TRUE(HasBOM); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1936 | - HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff ", 3)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1937 | + HasBOM = hasUTF16ByteOrderMark("\xfe\xff "); |
| 1938 | EXPECT_TRUE(HasBOM); // Don't care about odd lengths. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1939 | - HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe\xff\x00asdf", 6)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1940 | + HasBOM = hasUTF16ByteOrderMark("\xfe\xff\x00asdf"); |
| 1941 | EXPECT_TRUE(HasBOM); |
| 1942 | |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1943 | - HasBOM = hasUTF16ByteOrderMark(std::nullopt); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1944 | + HasBOM = hasUTF16ByteOrderMark(""); |
| 1945 | EXPECT_FALSE(HasBOM); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1946 | - HasBOM = hasUTF16ByteOrderMark(ArrayRef("\xfe", 1)); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1947 | + HasBOM = hasUTF16ByteOrderMark("\xfe"); |
| 1948 | EXPECT_FALSE(HasBOM); |
| 1949 | } |
| 1950 | |
| 1951 | TEST(ConvertUTFTest, UTF16WrappersForConvertUTF16ToUTF8String) { |
| 1952 | // Src is the look of disapproval. |
| 1953 | alignas(UTF16) static const char Src[] = "\xff\xfe\xa0\x0c_\x00\xa0\x0c"; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1954 | - ArrayRef<UTF16> SrcRef = ArrayRef((const UTF16 *)Src, 4); |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1955 | + span<const UTF16> SrcRef((const UTF16 *)Src, 4); |
| 1956 | std::string Result; |
| 1957 | bool Success = convertUTF16ToUTF8String(SrcRef, Result); |
| 1958 | EXPECT_TRUE(Success); |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1959 | @@ -123,7 +122,7 @@ TEST(ConvertUTFTest, ConvertUTF8toWide) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1960 | std::wstring Expected(L"\x0ca0_\x0ca0"); |
| 1961 | EXPECT_EQ(Expected, Result); |
| 1962 | Result.clear(); |
| 1963 | - Success = ConvertUTF8toWide(StringRef(Src, 7), Result); |
| 1964 | + Success = ConvertUTF8toWide(Src, Result); |
| 1965 | EXPECT_TRUE(Success); |
| 1966 | EXPECT_EQ(Expected, Result); |
| 1967 | } |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1968 | @@ -172,7 +171,7 @@ struct ConvertUTFResultContainer { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1969 | }; |
| 1970 | |
| 1971 | std::pair<ConversionResult, std::vector<unsigned>> |
| 1972 | -ConvertUTF8ToUnicodeScalarsLenient(StringRef S) { |
| 1973 | +ConvertUTF8ToUnicodeScalarsLenient(std::string_view S) { |
| 1974 | const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data()); |
| 1975 | |
| 1976 | const UTF8 *SourceNext = SourceStart; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1977 | @@ -189,7 +188,7 @@ ConvertUTF8ToUnicodeScalarsLenient(StringRef S) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | std::pair<ConversionResult, std::vector<unsigned>> |
| 1981 | -ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) { |
| 1982 | +ConvertUTF8ToUnicodeScalarsPartialLenient(std::string_view S) { |
| 1983 | const UTF8 *SourceStart = reinterpret_cast<const UTF8 *>(S.data()); |
| 1984 | |
| 1985 | const UTF8 *SourceNext = SourceStart; |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1986 | @@ -207,7 +206,7 @@ ConvertUTF8ToUnicodeScalarsPartialLenient(StringRef S) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1987 | |
| 1988 | ::testing::AssertionResult |
| 1989 | CheckConvertUTF8ToUnicodeScalars(ConvertUTFResultContainer Expected, |
| 1990 | - StringRef S, bool Partial = false) { |
| 1991 | + std::string_view S, bool Partial = false) { |
| 1992 | ConversionResult ErrorCode; |
| 1993 | std::vector<unsigned> Decoded; |
| 1994 | if (!Partial) |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1995 | @@ -302,7 +301,7 @@ TEST(ConvertUTFTest, UTF8ToUTF32Lenient) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 1996 | // U+0000 NULL |
| 1997 | EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( |
| 1998 | ConvertUTFResultContainer(conversionOK).withScalars(0x0000), |
| 1999 | - StringRef("\x00", 1))); |
| 2000 | + std::string_view("\x00", 1))); |
| 2001 | |
| 2002 | // U+0080 PADDING CHARACTER |
| 2003 | EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 2004 | @@ -1076,7 +1075,7 @@ TEST(ConvertUTFTest, UTF8ToUTF32Lenient) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 2005 | // U+0000 NULL |
| 2006 | EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( |
| 2007 | ConvertUTFResultContainer(conversionOK).withScalars(0x0000), |
| 2008 | - StringRef("\x00", 1))); |
| 2009 | + std::string_view("\x00", 1))); |
| 2010 | |
| 2011 | // Overlong sequences of the above. |
| 2012 | EXPECT_TRUE(CheckConvertUTF8ToUnicodeScalars( |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 2013 | diff --git a/llvm/unittests/Support/xxhashTest.cpp b/llvm/unittests/Support/xxhashTest.cpp |
| 2014 | index 7d78de6772b5159459572fe11633c76d04b86907..d61a5acd21f4d685ca631d3adb20c2649e050bc3 100644 |
| 2015 | --- a/llvm/unittests/Support/xxhashTest.cpp |
| 2016 | +++ b/llvm/unittests/Support/xxhashTest.cpp |
| 2017 | @@ -12,7 +12,7 @@ |
| 2018 | using namespace llvm; |
| 2019 | |
| 2020 | TEST(xxhashTest, Basic) { |
| 2021 | - EXPECT_EQ(0xef46db3751d8e999U, xxHash64(StringRef())); |
| 2022 | + EXPECT_EQ(0xef46db3751d8e999U, xxHash64(std::string_view())); |
| 2023 | EXPECT_EQ(0x33bf00a859c4ba3fU, xxHash64("foo")); |
| 2024 | EXPECT_EQ(0x48a37c90ad27a659U, xxHash64("bar")); |
| 2025 | EXPECT_EQ(0x69196c1b3af0bff9U, |
| 2026 | @@ -31,7 +31,7 @@ TEST(xxhashTest, xxh3) { |
| 2027 | } |
| 2028 | |
| 2029 | #define F(len, expected) \ |
| 2030 | - EXPECT_EQ(uint64_t(expected), xxh3_64bits(ArrayRef(a, size_t(len)))) |
| 2031 | + EXPECT_EQ(uint64_t(expected), xxh3_64bits(span(a, size_t(len)))) |
| 2032 | F(0, 0x2d06800538d394c2); |
| 2033 | F(1, 0xd0d496e05c553485); |
| 2034 | F(2, 0x84d625edb7055eac); |