Skip to content

Commit a4a7728

Browse files
kazutakahirataAnthony Tran
authored andcommitted
[Option] Use llvm::interlaved (NFC) (llvm#145642)
Note that llvm::interleaved constructs a string with the elements from a given range with a given separator.
1 parent eae30c3 commit a4a7728

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

llvm/lib/Option/Arg.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "llvm/Option/Arg.h"
910
#include "llvm/ADT/SmallString.h"
1011
#include "llvm/Config/llvm-config.h"
11-
#include "llvm/Option/Arg.h"
1212
#include "llvm/Option/ArgList.h"
1313
#include "llvm/Option/Option.h"
1414
#include "llvm/Support/Compiler.h"
1515
#include "llvm/Support/Debug.h"
16+
#include "llvm/Support/InterleavedRange.h"
1617
#include "llvm/Support/raw_ostream.h"
1718

1819
using namespace llvm;
@@ -72,13 +73,7 @@ std::string Arg::getAsString(const ArgList &Args) const {
7273

7374
ArgStringList ASL;
7475
render(Args, ASL);
75-
for (ArgStringList::iterator
76-
it = ASL.begin(), ie = ASL.end(); it != ie; ++it) {
77-
if (it != ASL.begin())
78-
OS << ' ';
79-
OS << *it;
80-
}
81-
76+
OS << llvm::interleaved(ASL, " ");
8277
return std::string(OS.str());
8378
}
8479

@@ -100,11 +95,7 @@ void Arg::render(const ArgList &Args, ArgStringList &Output) const {
10095
case Option::RenderCommaJoinedStyle: {
10196
SmallString<256> Res;
10297
raw_svector_ostream OS(Res);
103-
OS << getSpelling();
104-
for (unsigned i = 0, e = getNumValues(); i != e; ++i) {
105-
if (i) OS << ',';
106-
OS << getValue(i);
107-
}
98+
OS << getSpelling() << llvm::interleaved(getValues(), ",");
10899
Output.push_back(Args.MakeArgString(OS.str()));
109100
break;
110101
}

0 commit comments

Comments
 (0)