Skip to content

Commit ec3c63a

Browse files
committed
Swift: replace all usages of std::to_string with absl::StrCat or absl::StrAppend
1 parent 84c0170 commit ec3c63a

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

swift/extractor/infra/SwiftDispatcher.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <swift/AST/SourceFile.h>
66
#include <swift/Basic/SourceManager.h>
77
#include <swift/Parse/Token.h>
8+
#include "absl/strings/str_cat.h"
89

910
#include "swift/extractor/trap/TrapDomain.h"
1011
#include "swift/extractor/infra/SwiftTagTraits.h"
@@ -83,7 +84,7 @@ class SwiftDispatcher {
8384
valid = false;
8485
}
8586
LOG_ERROR("{} has undefined field {}{}, {}", entry.NAME, field,
86-
index >= 0 ? ('[' + std::to_string(index) + ']') : "", action);
87+
index >= 0 ? absl::StrCat("[", index, "]") : "", action);
8788
}
8889
});
8990
if (valid) {

swift/extractor/infra/SwiftMangledName.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "swift/extractor/infra/SwiftMangledName.h"
2+
#include "absl/strings/str_cat.h"
23

34
namespace codeql {
45

@@ -8,13 +9,11 @@ void appendPart(std::string& out, const std::string& prefix) {
89
}
910

1011
void appendPart(std::string& out, UntypedTrapLabel label) {
11-
out += '{';
12-
out += label.str();
13-
out += '}';
12+
absl::StrAppend(&out, "{", label.str(), "}");
1413
}
1514

1615
void appendPart(std::string& out, unsigned index) {
17-
out += std::to_string(index);
16+
absl::StrAppend(&out, index);
1817
}
1918

2019
} // namespace

swift/extractor/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <swift/Basic/InitializeSwiftModules.h>
1111

1212
#include "absl/strings/str_join.h"
13+
#include "absl/strings/str_cat.h"
1314

1415
#include "swift/extractor/SwiftExtractor.h"
1516
#include "swift/extractor/infra/TargetDomains.h"
@@ -166,7 +167,7 @@ static void checkWhetherToRunUnderTool(int argc, char* const* argv) {
166167
// compilations, diagnostics, etc.
167168
codeql::TrapDomain invocationTrapDomain(codeql::SwiftExtractorState& state) {
168169
auto timestamp = std::chrono::system_clock::now().time_since_epoch().count();
169-
auto filename = std::to_string(timestamp) + '-' + std::to_string(getpid());
170+
auto filename = absl::StrCat(timestamp, "-", getpid());
170171
auto target = std::filesystem::path("invocations") / std::filesystem::path(filename);
171172
auto maybeDomain = codeql::createTargetTrapDomain(state, target, codeql::TrapType::invocation);
172173
CODEQL_ASSERT(maybeDomain, "Cannot create invocation trap file for {}", target);

swift/extractor/trap/TrapDomain.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <memory>
44
#include <sstream>
5+
#include "absl/strings/str_cat.h"
56

67
#include "swift/extractor/trap/TrapLabel.h"
78
#include "swift/extractor/infra/file/TargetFile.h"
@@ -27,7 +28,7 @@ class TrapDomain {
2728
e.forEachLabel([&e, this](const char* field, int index, auto& label) {
2829
if (!label.valid()) {
2930
LOG_ERROR("{} has undefined field {}{}", e.NAME, field,
30-
index >= 0 ? ('[' + std::to_string(index) + ']') : "");
31+
index >= 0 ? absl::StrCat("[", index, "]") : "");
3132
}
3233
});
3334
}

swift/logging/SwiftLogging.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdlib.h>
55
#include <optional>
66
#include <unistd.h>
7+
#include "absl/strings/str_cat.h"
78

89
#define LEVEL_REGEX_PATTERN "trace|debug|info|warning|error|critical|no_logs"
910

@@ -98,9 +99,8 @@ std::vector<std::string> Log::collectLevelRulesAndReturnProblems(const char* env
9899
void Log::configure() {
99100
// as we are configuring logging right now, we collect problems and log them at the end
100101
auto problems = collectLevelRulesAndReturnProblems("CODEQL_EXTRACTOR_SWIFT_LOG_LEVELS");
101-
auto logBaseName = std::to_string(std::chrono::system_clock::now().time_since_epoch().count());
102-
logBaseName += '-';
103-
logBaseName += std::to_string(getpid());
102+
auto timestamp = std::chrono::system_clock::now().time_since_epoch().count();
103+
auto logBaseName = absl::StrCat(timestamp, "-", getpid());
104104
if (text || binary) {
105105
std::filesystem::path logFile = getEnvOr("CODEQL_EXTRACTOR_SWIFT_LOG_DIR", "extractor-out/log");
106106
logFile /= "swift";

0 commit comments

Comments
 (0)