Skip to content

Commit 7a773cd

Browse files
committed
More stuff moved over to SmallString
1 parent f464be1 commit 7a773cd

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

lib/Basic/Version.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "llvm/ADT/StringExtras.h"
2323
#include "llvm/Support/raw_ostream.h"
2424

25+
#include <array>
26+
#include <cstring>
2527
#include <vector>
2628

2729
#define TOSTR2(X) #X
@@ -90,6 +92,26 @@ raw_ostream &operator<<(raw_ostream &os, const Version &version) {
9092
return os;
9193
}
9294

95+
template <size_t InternalLen>
96+
static SmallString<InternalLen> &operator +=(SmallString<InternalLen> &buf, unsigned int value) {
97+
std::array<char, 64> valueBuf;
98+
snprintf(valueBuf.data(), valueBuf.size(), "%u", value);
99+
buf += valueBuf.data();
100+
return buf;
101+
}
102+
103+
template <size_t InternalLen>
104+
static SmallString<InternalLen> &operator +=(SmallString<InternalLen> &buf, const Version &version) {
105+
if (version.empty())
106+
return buf;
107+
buf += version[0];
108+
for (size_t i = 1, e = version.size(); i != e; ++i) {
109+
buf += ".";
110+
buf += version[i];
111+
}
112+
return os;
113+
}
114+
93115
std::string
94116
Version::preprocessorDefinition(StringRef macroName,
95117
ArrayRef<uint64_t> componentWeights) const {
@@ -277,7 +299,8 @@ static SmallString<256> getSwiftFullVersionImpl(Version effectiveVersion) {
277299
#endif
278300

279301
if (effectiveVersion != Version::getCurrentLanguageVersion()) {
280-
buf += " effective-" << effectiveVersion;
302+
buf += " effective-";
303+
buf += effectiveVersion;
281304
}
282305

283306
#if defined(SWIFT_COMPILER_VERSION)

0 commit comments

Comments
 (0)