write rfind in terms of npos as daniel requested
authorChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 22:54:26 +0000 (22:54 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 20 Sep 2009 22:54:26 +0000 (22:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82414 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringRef.h

index 510a51b4c653a8149d7d491b201a5028c777f6fd..e4fd258cb87182ef27a6c01e0ec5554f2eb4ff41 100644 (file)
@@ -169,8 +169,10 @@ namespace llvm {
     ///
     /// \return - The index of the last occurence of \arg C, or npos if not
     /// found.
     ///
     /// \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;
         --i;
         if (Data[i] == C)
           return i;
@@ -178,10 +180,6 @@ namespace llvm {
       return npos;
     }
     
       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
     /// 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