diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h index 2d2f0bedfe1f82..868722e19001c9 100644 --- a/llvm/include/llvm/ADT/StringRef.h +++ b/llvm/include/llvm/ADT/StringRef.h @@ -343,12 +343,11 @@ namespace llvm { /// \returns The index of the last occurrence of \p C, or npos if not /// found. [[nodiscard]] size_t rfind(char C, size_t From = npos) const { - From = std::min(From, Length); - size_t i = From; - while (i != 0) { - --i; - if (Data[i] == C) - return i; + size_t I = std::min(From, Length); + while (I) { + --I; + if (Data[I] == C) + return I; } return npos; } @@ -449,8 +448,8 @@ namespace llvm { /// Return the number of occurrences of \p C in the string. [[nodiscard]] size_t count(char C) const { size_t Count = 0; - for (size_t i = 0, e = Length; i != e; ++i) - if (Data[i] == C) + for (size_t I = 0; I != Length; ++I) + if (Data[I] == C) ++Count; return Count; } @@ -624,7 +623,7 @@ namespace llvm { if (!starts_with(Prefix)) return false; - *this = drop_front(Prefix.size()); + *this = substr(Prefix.size()); return true; } @@ -634,7 +633,7 @@ namespace llvm { if (!startswith_insensitive(Prefix)) return false; - *this = drop_front(Prefix.size()); + *this = substr(Prefix.size()); return true; } @@ -644,7 +643,7 @@ namespace llvm { if (!ends_with(Suffix)) return false; - *this = drop_back(Suffix.size()); + *this = substr(0, size() - Suffix.size()); return true; } @@ -654,7 +653,7 @@ namespace llvm { if (!endswith_insensitive(Suffix)) return false; - *this = drop_back(Suffix.size()); + *this = substr(0, size() - Suffix.size()); return true; } @@ -671,7 +670,7 @@ namespace llvm { /// be returned. [[nodiscard]] StringRef slice(size_t Start, size_t End) const { Start = std::min(Start, Length); - End = std::min(std::max(Start, End), Length); + End = std::clamp(End, Start, Length); return StringRef(Data + Start, End - Start); }