Skip to content

Commit 2b3e53a

Browse files
committed
AST: simplify debug flag computation
Use an algorithmic approach to string concatenation rather than building the space delimited string manually. This allows us to extend the flags embedding more easily in the future.
1 parent b580e7c commit 2b3e53a

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/Support/raw_ostream.h"
3333
#include "llvm/Support/VersionTuple.h"
3434
#include <optional>
35+
#include <sstream>
3536
#include <string>
3637
#include <tuple>
3738
#include <vector>
@@ -656,24 +657,21 @@ class IRGenOptions {
656657
std::string getDebugFlags(StringRef PrivateDiscriminator,
657658
bool EnableCXXInterop,
658659
bool EnableEmbeddedSwift) const {
659-
std::string Flags = DebugFlags;
660+
llvm::SmallVector<std::string, 4> Flags{DebugFlags};
661+
660662
if (!PrivateDiscriminator.empty()) {
661-
if (!Flags.empty())
662-
Flags += " ";
663-
Flags += ("-private-discriminator " + PrivateDiscriminator).str();
664-
}
665-
if (EnableCXXInterop) {
666-
if (!Flags.empty())
667-
Flags += " ";
668-
Flags += "-enable-experimental-cxx-interop";
663+
Flags.emplace_back("-private-discriminator");
664+
Flags.emplace_back(PrivateDiscriminator);
669665
}
670-
if (EnableEmbeddedSwift) {
671-
if (!Flags.empty())
672-
Flags += " ";
673-
Flags += "-enable-embedded-swift";
674-
}
675-
676-
return Flags;
666+
if (EnableCXXInterop)
667+
Flags.emplace_back("-enable-experimental-cxx-interop");
668+
if (EnableEmbeddedSwift)
669+
Flags.emplace_back("-enable-embedded-swift");
670+
671+
std::ostringstream buffer;
672+
std::copy(std::begin(Flags), std::end(Flags),
673+
std::ostream_iterator<std::string>(buffer, " "));
674+
return buffer.str();
677675
}
678676

679677
/// Return a hash code of any components from these options that should

0 commit comments

Comments
 (0)