From c936fe8cb356931f23e6f17ce1bd5789eeae1ecb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 20 Sep 2009 22:54:26 +0000 Subject: [PATCH] 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 --- include/llvm/ADT/StringRef.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 510a51b4c65..e4fd258cb87 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 -- 2.34.1