Skip to content

Commit 74049d4

Browse files
lint?
1 parent 2ec3a7a commit 74049d4

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

benchmarks/data_track_throughput/consumer.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ bool parseArgs(int argc, char *argv[], ConsumerOptions &options) {
102102
}
103103
return {};
104104
};
105+
auto matchingOutputFlag = [](const std::string &arg) -> const char * {
106+
static constexpr const char *kOutputFlags[] = {"--output-dir", "--output",
107+
"--ouput"};
108+
for (const char *flag : kOutputFlags) {
109+
if (arg.rfind(flag, 0) == 0) {
110+
return flag;
111+
}
112+
}
113+
return nullptr;
114+
};
105115

106116
for (int index = 1; index < argc; ++index) {
107117
const std::string arg = argv[index];
@@ -113,12 +123,9 @@ bool parseArgs(int argc, char *argv[], ConsumerOptions &options) {
113123
options.url = readFlagValue("--url", index);
114124
} else if (arg.rfind("--token", 0) == 0) {
115125
options.token = readFlagValue("--token", index);
116-
} else if (arg.rfind("--output-dir", 0) == 0) {
117-
options.output_dir = readFlagValue("--output-dir", index);
118-
} else if (arg.rfind("--output", 0) == 0) {
119-
options.output_dir = readFlagValue("--output", index);
120-
} else if (arg.rfind("--ouput", 0) == 0) {
121-
options.output_dir = readFlagValue("--ouput", index);
126+
} else if (const char *output_flag = matchingOutputFlag(arg);
127+
output_flag != nullptr) {
128+
options.output_dir = readFlagValue(output_flag, index);
122129
} else if (arg.rfind("--track-name", 0) == 0) {
123130
options.track_name = readFlagValue("--track-name", index);
124131
} else if (arg.rfind("--quiet-period-ms", 0) == 0) {
@@ -423,7 +430,8 @@ class ThroughputConsumer {
423430
}
424431

425432
void appendSummaryRow(const json &summary) const {
426-
std::ofstream out(summary_csv_path_, std::ios::app);
433+
std::ofstream out;
434+
out.open(summary_csv_path_, std::ios::app);
427435
if (!out) {
428436
throw std::runtime_error("Failed to open summary CSV for append");
429437
}
@@ -455,7 +463,8 @@ class ThroughputConsumer {
455463
return lhs.arrival_time_us < rhs.arrival_time_us;
456464
});
457465

458-
std::ofstream out(message_csv_path_, std::ios::app);
466+
std::ofstream out;
467+
out.open(message_csv_path_, std::ios::app);
459468
if (!out) {
460469
throw std::runtime_error("Failed to open message CSV for append");
461470
}

benchmarks/data_track_throughput/producer.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <exception>
2424
#include <iostream>
2525
#include <optional>
26-
#include <sstream>
2726
#include <string>
2827
#include <thread>
2928
#include <vector>
@@ -76,10 +75,16 @@ void printUsage(const char *prog) {
7675

7776
std::vector<std::string> splitCommaSeparated(const std::string &text) {
7877
std::vector<std::string> values;
79-
std::stringstream stream(text);
80-
std::string value;
81-
while (std::getline(stream, value, ',')) {
82-
values.push_back(trim(value));
78+
std::size_t start = 0;
79+
while (start < text.size()) {
80+
const std::size_t end = text.find(',', start);
81+
const std::size_t count =
82+
end == std::string::npos ? std::string::npos : end - start;
83+
values.push_back(trim(text.substr(start, count)));
84+
if (end == std::string::npos) {
85+
break;
86+
}
87+
start = end + 1;
8388
}
8489
return values;
8590
}

0 commit comments

Comments
 (0)