Skip to content

Commit

Permalink
refactor: Change C-style casts to C++-style
Browse files Browse the repository at this point in the history
  • Loading branch information
jkhaliqi committed Dec 10, 2024
1 parent cd9f2dd commit a3998f5
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,15 @@ void PeriodicTaskManager::updateOperatingSystemStats() {
getrusage(RUSAGE_SELF, &usage);

const int64_t userCpuTimeUs{
(int64_t)usage.ru_utime.tv_sec * 1'000'000 +
(int64_t)usage.ru_utime.tv_usec};
static_cast<int64_t>(usage.ru_utime.tv_sec) * 1'000'000 +
static_cast<int64_t>(usage.ru_utime.tv_usec)};
RECORD_METRIC_VALUE(
kCounterOsUserCpuTimeMicros, userCpuTimeUs - lastUserCpuTimeUs_);
lastUserCpuTimeUs_ = userCpuTimeUs;

const int64_t systemCpuTimeUs{
(int64_t)usage.ru_stime.tv_sec * 1'000'000 +
(int64_t)usage.ru_stime.tv_usec};
static_cast<int64_t>(usage.ru_stime.tv_sec) * 1'000'000 +
static_cast<int64_t>(usage.ru_stime.tv_usec)};
RECORD_METRIC_VALUE(
kCounterOsSystemCpuTimeMicros, systemCpuTimeUs - lastSystemCpuTimeUs_);
lastSystemCpuTimeUs_ = systemCpuTimeUs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ std::string bodyAsString(
std::ostringstream oss;
auto iobufs = response.consumeBody();
for (auto& body : iobufs) {
oss << std::string((const char*)body->data(), body->length());
oss << std::string(
reinterpret_cast<const char*>(body->data()), body->length());
if (pool != nullptr) {
pool->free(body->writableData(), body->capacity());
}
Expand Down
4 changes: 2 additions & 2 deletions presto-native-execution/presto_cpp/main/http/HttpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ void HttpServer::start(
options.handlerFactories = handlerFactories.build();

// Increase the default flow control to 1MB/10MB
options.initialReceiveWindow = uint32_t(1 << 20);
options.receiveStreamWindowSize = uint32_t(1 << 20);
options.initialReceiveWindow = static_cast<uint32_t>(1 << 20);
options.receiveStreamWindowSize = static_cast<uint32_t>(1 << 20);
options.receiveSessionWindowSize = 10 * (1 << 20);
options.h2cEnabled = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ class BroadcastTest : public exec::test::OperatorTestBase {
std::vector<ByteRange> ranges;
for (const auto& range : *ioBuf) {
ranges.emplace_back(ByteRange{
const_cast<uint8_t*>(range.data()), (int32_t)range.size(), 0});
const_cast<uint8_t*>(range.data()),
static_cast<int32_t>(range.size(), 0)});
}
auto byteStream = std::make_unique<BufferInputStream>(std::move(ranges));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void PrometheusStatsReporter::registerHistogramMetricExportType(
.Register(*impl_->registry);
::prometheus::Summary::Quantiles quantiles;
for (auto pct : pcts) {
quantiles.push_back(
::prometheus::detail::CKMSQuantiles::Quantile(pct / (double)100, 0));
quantiles.push_back(::prometheus::detail::CKMSQuantiles::Quantile(
pct / static_cast<double>(100), 0));
}
auto& summaryMetric = summaryFamily.Add({impl_->labels}, quantiles);
registeredMetricsMap_.emplace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ TEST_F(QueryContextCacheTest, basic) {
for (int i = 0; i < 16; ++i) {
auto queryId = fmt::format("query-{}", i);
auto queryCtx = core::QueryCtx::create(
(folly::Executor*)nullptr, core::QueryConfig({}));
static_cast<folly::Executor*>(nullptr), core::QueryConfig({}));
queryCtxs[queryId] = queryCtx;
queryContextCache.insert(queryId, queryCtx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ class Cursor {
std::vector<ByteRange> byteRanges;
for (auto& range : *buffer) {
byteRanges.emplace_back(ByteRange{
const_cast<uint8_t*>(range.data()), (int32_t)range.size(), 0});
const_cast<uint8_t*>(range.data()),
static_cast<int32_t>(range.size()),
0});
}

const auto input =
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RowTypePtr toRowType(

template <typename T>
std::string toJsonString(const T& value) {
return ((json)value).dump();
return (static_cast<json>(value)).dump();
}

std::shared_ptr<connector::ColumnHandle> toColumnHandle(
Expand Down Expand Up @@ -1736,7 +1736,8 @@ core::ExecutionStrategy toStrategy(protocol::StageExecutionStrategy strategy) {
"RECOVERABLE_GROUPED_EXECUTION "
"Stage Execution Strategy is not supported");
}
VELOX_UNSUPPORTED("Unknown Stage Execution Strategy type {}", (int)strategy);
VELOX_UNSUPPORTED(
"Unknown Stage Execution Strategy type {}", static_cast<int>(strategy));
}

// Presto doesn't have PartitionedOutputNode and assigns its source node's plan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {
std::unique_ptr<ByteInputStream> toByteStream(const std::string& input) {
ByteRange byteRange{
reinterpret_cast<uint8_t*>(const_cast<char*>(input.data())),
(int32_t)input.length(),
static_cast<int32_t>(input.length()),
0};
return std::make_unique<BufferInputStream>(std::vector<ByteRange>{byteRange});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ TEST_F(VariableReferenceExpressionTest, basic) {
testJsonRoundtrip(j, p);

ASSERT_EQ(json_map_key(p), "segment<integer>") << "... json_map_key";
ASSERT_EQ((json)VariableReferenceExpression("segment<integer>"), (json)p)
ASSERT_EQ(
static_cast<json>(VariableReferenceExpression("segment<integer>")),
(json)p)
<< "... string constructor";
}

0 comments on commit a3998f5

Please sign in to comment.