[Support] Use ListSeparator (NFC)
authorKazu Hirata <kazu@google.com>
Mon, 15 Feb 2021 22:46:09 +0000 (14:46 -0800)
committerKazu Hirata <kazu@google.com>
Mon, 15 Feb 2021 22:46:09 +0000 (14:46 -0800)
llvm/include/llvm/Support/ScopedPrinter.h

index c5e5386ce21deba1ae9415ceb27a963b2d535a73..fe800e324047026dcee8aafa460329a2f8716b3e 100644 (file)
@@ -12,6 +12,7 @@
 #include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/Endian.h"
@@ -207,38 +208,28 @@ public:
 
   template <typename T> void printList(StringRef Label, const T &List) {
     startLine() << Label << ": [";
-    bool Comma = false;
-    for (const auto &Item : List) {
-      if (Comma)
-        OS << ", ";
-      OS << Item;
-      Comma = true;
-    }
+    ListSeparator LS;
+    for (const auto &Item : List)
+      OS << LS << Item;
     OS << "]\n";
   }
 
   template <typename T, typename U>
   void printList(StringRef Label, const T &List, const U &Printer) {
     startLine() << Label << ": [";
-    bool Comma = false;
+    ListSeparator LS;
     for (const auto &Item : List) {
-      if (Comma)
-        OS << ", ";
+      OS << LS;
       Printer(OS, Item);
-      Comma = true;
     }
     OS << "]\n";
   }
 
   template <typename T> void printHexList(StringRef Label, const T &List) {
     startLine() << Label << ": [";
-    bool Comma = false;
-    for (const auto &Item : List) {
-      if (Comma)
-        OS << ", ";
-      OS << hex(Item);
-      Comma = true;
-    }
+    ListSeparator LS;
+    for (const auto &Item : List)
+      OS << LS << hex(Item);
     OS << "]\n";
   }