aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-09-20 22:54:26 +0000
committerChris Lattner <sabre@nondot.org>2009-09-20 22:54:26 +0000
commitc936fe8cb356931f23e6f17ce1bd5789eeae1ecb (patch)
tree16b01f3f40000e2e99d42a160ddbf175167c8eb4
parent19e74991f304a67c4dddbea12f1d9f71446ba2a0 (diff)
write rfind in terms of npos as daniel requested
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82414 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/ADT/StringRef.h10
1 files changed, 4 insertions, 6 deletions
diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h
index 510a51b4c6..e4fd258cb8 100644
--- a/include/llvm/ADT/StringRef.h
+++ b/include/llvm/ADT/StringRef.h
@@ -169,8 +169,10 @@ namespace llvm {
///
/// \return - The index of the last occurence of \arg C, or npos if not
/// found.
- size_t rfind(char C, size_t From) const {
- for (size_t i = From, e = 0; i != e;) {
+ 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;
@@ -178,10 +180,6 @@ namespace llvm {
return npos;
}
- size_t rfind(char C) const {
- return rfind(C, Length);
- }
-
/// rfind - Search for the last string \arg Str in the string.
///
/// \return - The index of the last occurence of \arg Str, or npos if not