[PGO] Simplify string parsing
authorXinliang David Li <davidxl@google.com>
Mon, 4 Jan 2016 22:09:26 +0000 (22:09 +0000)
committerXinliang David Li <davidxl@google.com>
Mon, 4 Jan 2016 22:09:26 +0000 (22:09 +0000)
Patch Suggested by Vedant.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256785 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ProfileData/InstrProf.cpp

index bcb248e..027f0f7 100644 (file)
@@ -245,20 +245,10 @@ int readPGOFuncNameStrings(StringRef NameStrings, InstrProfSymtab &Symtab) {
       P += UncompressedSize;
     }
     // Now parse the name strings.
-    size_t NameStart = 0;
-    bool isLast = false;
-    do {
-      size_t NameStop = NameStrings.find(' ', NameStart);
-      if (NameStop == StringRef::npos)
-        NameStop = NameStrings.size();
-      if (NameStop >= NameStrings.size() - 1)
-        isLast = true;
-      StringRef Name = NameStrings.substr(NameStart, NameStop - NameStart);
+    SmallVector<StringRef, 0> Names;
+    NameStrings.split(Names, ' ');
+    for (StringRef &Name : Names)
       Symtab.addFuncName(Name);
-      if (isLast)
-        break;
-      NameStart = NameStop + 1;
-    } while (true);
 
     while (P < EndP && *P == 0)
       P++;