[llvm] r208723 - Make the split function use StringRef::split.

Eric Christopher echristo at gmail.com
Tue May 13 12:55:17 PDT 2014


Author: echristo
Date: Tue May 13 14:55:17 2014
New Revision: 208723

URL: http://llvm.org/viewvc/llvm-project?rev=208723&view=rev
Log:
Make the split function use StringRef::split.

Modified:
    llvm/trunk/lib/MC/SubtargetFeature.cpp

Modified: llvm/trunk/lib/MC/SubtargetFeature.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/SubtargetFeature.cpp?rev=208723&r1=208722&r2=208723&view=diff
==============================================================================
--- llvm/trunk/lib/MC/SubtargetFeature.cpp (original)
+++ llvm/trunk/lib/MC/SubtargetFeature.cpp Tue May 13 14:55:17 2014
@@ -54,25 +54,9 @@ static inline bool isEnabled(const Strin
 /// Split - Splits a string of comma separated items in to a vector of strings.
 ///
 static void Split(std::vector<std::string> &V, const StringRef S) {
-  if (S.empty())
-    return;
-
-  // Start at beginning of string.
-  size_t Pos = 0;
-  while (true) {
-    // Find the next comma
-    size_t Comma = S.find(',', Pos);
-    // If no comma found then the rest of the string is used
-    if (Comma == std::string::npos) {
-      // Add string to vector
-      V.push_back(S.substr(Pos));
-      break;
-    }
-    // Otherwise add substring to vector
-    V.push_back(S.substr(Pos, Comma - Pos));
-    // Advance to next item
-    Pos = Comma + 1;
-  }
+  SmallVector<StringRef, 2> Tmp;
+  S.split(Tmp, ",", -1, false /* KeepEmpty */);
+  V.assign(Tmp.begin(), Tmp.end());
 }
 
 /// Join a vector of strings to a string with a comma separating each element.





More information about the llvm-commits mailing list