[llvm-commits] [llvm] r87068 - in /llvm/trunk: include/llvm/ADT/StringRef.h lib/Support/StringExtras.cpp unittests/ADT/StringRefTest.cpp

Rafael Espindola rafael.espindola at gmail.com
Thu Nov 12 18:18:25 PST 2009


Author: rafael
Date: Thu Nov 12 20:18:25 2009
New Revision: 87068

URL: http://llvm.org/viewvc/llvm-project?rev=87068&view=rev
Log:

Switch to smallvector. Also fix issue with using unsigend for MaxSplit.

Modified:
    llvm/trunk/include/llvm/ADT/StringRef.h
    llvm/trunk/lib/Support/StringExtras.cpp
    llvm/trunk/unittests/ADT/StringRefTest.cpp

Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=87068&r1=87067&r2=87068&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Thu Nov 12 20:18:25 2009
@@ -15,15 +15,9 @@
 #include <cstring>
 #include <string>
 
-namespace std {
- template<typename _Tp>
- class allocator;
-
- template<typename _Tp, typename _Alloc>
- class vector;
-}
-
 namespace llvm {
+  template<typename T>
+  class SmallVectorImpl;
 
   /// StringRef - Represent a constant reference to a string, i.e. a character
   /// array and a length, which need not be null terminated.
@@ -337,8 +331,8 @@
     /// \param Separator - The string to split on.
     /// \param MaxSplit - The maximum number of times the string is split.
     /// \parm KeepEmpty - True if empty substring should be added.
-    void split(std::vector<StringRef, std::allocator<StringRef> > &A,
-               StringRef Separator, unsigned MaxSplit = -1,
+    void split(SmallVectorImpl<StringRef> &A,
+               StringRef Separator, int MaxSplit = -1,
                bool KeepEmpty = true) const;
 
     /// rsplit - Split into two substrings around the last occurence of a

Modified: llvm/trunk/lib/Support/StringExtras.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringExtras.cpp?rev=87068&r1=87067&r2=87068&view=diff

==============================================================================
--- llvm/trunk/lib/Support/StringExtras.cpp (original)
+++ llvm/trunk/lib/Support/StringExtras.cpp Thu Nov 12 20:18:25 2009
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include <cstring>
 using namespace llvm;
 
@@ -57,12 +58,12 @@
   }
 }
 
-void llvm::StringRef::split(std::vector<StringRef> &A,
-                            StringRef Separators, unsigned MaxSplit,
+void llvm::StringRef::split(SmallVectorImpl<StringRef> &A,
+                            StringRef Separators, int MaxSplit,
                             bool KeepEmpty) const {
   StringRef rest = *this;
 
-  for (unsigned splits = 0;
+  for (int splits = 0;
        rest.size() != 0 && (MaxSplit < 0 || splits < MaxSplit);
        ++splits) {
     std::pair<llvm::StringRef, llvm::StringRef> p = rest.split(Separators);

Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=87068&r1=87067&r2=87068&view=diff

==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Thu Nov 12 20:18:25 2009
@@ -9,6 +9,7 @@
 
 #include "gtest/gtest.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
 
@@ -111,8 +112,8 @@
 }
 
 TEST(StringRefTest, Split2) {
-  std::vector<StringRef> parts;
-  std::vector<StringRef> expected;
+  SmallVector<StringRef, 5> parts;
+  SmallVector<StringRef, 5> expected;
 
   expected.push_back("ab"); expected.push_back("c");
   StringRef(",ab,,c,").split(parts, ",", -1, false);





More information about the llvm-commits mailing list