diff --git a/include/llvm/ADT/StringRef.h b/include/llvm/ADT/StringRef.h index 6ccb37d346c..6b17eb22de7 100644 --- a/include/llvm/ADT/StringRef.h +++ b/include/llvm/ADT/StringRef.h @@ -15,15 +15,9 @@ #include #include -namespace std { - template - class allocator; - - template - class vector; -} - namespace llvm { + template + 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 @@ namespace llvm { /// \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 > &A, - StringRef Separator, unsigned MaxSplit = -1, + void split(SmallVectorImpl &A, + StringRef Separator, int MaxSplit = -1, bool KeepEmpty = true) const; /// rsplit - Split into two substrings around the last occurence of a diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp index 05ba34b2e7b..687394a2fce 100644 --- a/lib/Support/StringExtras.cpp +++ b/lib/Support/StringExtras.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/SmallVector.h" #include using namespace llvm; @@ -57,12 +58,12 @@ void llvm::SplitString(const std::string &Source, } } -void llvm::StringRef::split(std::vector &A, - StringRef Separators, unsigned MaxSplit, +void llvm::StringRef::split(SmallVectorImpl &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 p = rest.split(Separators); diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 3c0cc58ad2d..ea1d26cb600 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -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, Split) { } TEST(StringRefTest, Split2) { - std::vector parts; - std::vector expected; + SmallVector parts; + SmallVector expected; expected.push_back("ab"); expected.push_back("c"); StringRef(",ab,,c,").split(parts, ",", -1, false);