[PATCH] D144787: [NFC][ADT] Tweaked some functions in StringRef
Shao-Ce SUN via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 16 10:45:35 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56686ec47ee0: [NFC][ADT] Tweaked some functions in StringRef (authored by sunshaoce).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144787/new/
https://reviews.llvm.org/D144787
Files:
llvm/include/llvm/ADT/StringRef.h
Index: llvm/include/llvm/ADT/StringRef.h
===================================================================
--- llvm/include/llvm/ADT/StringRef.h
+++ llvm/include/llvm/ADT/StringRef.h
@@ -343,12 +343,11 @@
/// \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 @@
/// 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 @@
if (!starts_with(Prefix))
return false;
- *this = drop_front(Prefix.size());
+ *this = substr(Prefix.size());
return true;
}
@@ -634,7 +633,7 @@
if (!startswith_insensitive(Prefix))
return false;
- *this = drop_front(Prefix.size());
+ *this = substr(Prefix.size());
return true;
}
@@ -644,7 +643,7 @@
if (!ends_with(Suffix))
return false;
- *this = drop_back(Suffix.size());
+ *this = substr(0, size() - Suffix.size());
return true;
}
@@ -654,7 +653,7 @@
if (!endswith_insensitive(Suffix))
return false;
- *this = drop_back(Suffix.size());
+ *this = substr(0, size() - Suffix.size());
return true;
}
@@ -671,7 +670,7 @@
/// 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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144787.505874.patch
Type: text/x-patch
Size: 2126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230316/b8b6c493/attachment.bin>
More information about the llvm-commits
mailing list