Skip to content

Commit

Permalink
Fix modernize-loop-convert warning reported by clang-tidy (#1112)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximSmolskiy authored Nov 16, 2022
1 parent a93fba9 commit 0c4d4b7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# refer to https://clang.llvm.org/extra/clang-tidy/checks/list.html
Checks: -*, clang-analyzer-core.*, clang-analyzer-cplusplus.*, clang-analyzer-deadcode.*, clang-analyzer-nullability.*, clang-analyzer-security.*, clang-analyzer-unix.*, clang-analyzer-valist.*, cppcoreguidelines-init-variables, cppcoreguidelines-macro-usage, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-narrowing-conversions, cppcoreguidelines-no-malloc, cppcoreguidelines-prefer-member-initializer, cppcoreguidelines-special-member-functions, cppcoreguidelines-slicing, google-build-explicit-make-pair, google-default-arguments, google-explicit-constructor, modernize-avoid-bind, modernize-loop-convert, modernize-macro-to-enum, modernize-make-shared, modernize-make-unique, modernize-pass-by-value, modernize-redundant-void-arg, modernize-return-braced-init-list, modernize-use-auto, modernize-use-bool-literals, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, modernize-use-nullptr, modernize-use-override, modernize-use-using, performance-faster-string-find, performance-for-range-copy, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-inefficient-vector-operation, performance-move-const-arg, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, performance-unnecessary-value-param

WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions
WarningsAsErrors: clang-analyzer-*, -clang-analyzer-security.insecureAPI.rand, cppcoreguidelines-interfaces-global-init, cppcoreguidelines-no-malloc, cppcoreguidelines-slicing, google-*, modernize-use-emplace, modernize-use-equals-default, modernize-use-equals-delete, performance-implicit-conversion-in-loop, performance-inefficient-algorithm, performance-move-constructor-init, performance-no-automatic-move, performance-trivially-destructible, performance-type-promotion-in-math-fn, performance-unnecessary-copy-initialization, modernize-use-bool-literals, performance-unnecessary-value-param, modernize-make-unique, performance-for-range-copy, performance-faster-string-find, modernize-redundant-void-arg, modernize-avoid-bind, modernize-use-auto, modernize-use-using, performance-inefficient-vector-operation, cppcoreguidelines-special-member-functions, modernize-loop-convert

CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
Expand Down
4 changes: 2 additions & 2 deletions src/common/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ void TaskRunner::Stop() {
}

void TaskRunner::Join() {
for (size_t i = 0; i < threads_.size(); i++) {
if (threads_[i].joinable()) threads_[i].join();
for (auto &thread : threads_) {
if (thread.joinable()) thread.join();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/stats/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Stats::Stats() {
im.last_sample_time = 0;
im.last_sample_count = 0;
im.idx = 0;
for (int j = 0; j < STATS_METRIC_SAMPLES; j++) {
im.samples[j] = 0;
for (uint64_t &sample : im.samples) {
sample = 0;
}
inst_metrics.push_back(im);
}
Expand Down Expand Up @@ -105,6 +105,6 @@ void Stats::TrackInstantaneousMetric(int metric, uint64_t current_reading) {

uint64_t Stats::GetInstantaneousMetric(int metric) {
uint64_t sum = 0;
for (int j = 0; j < STATS_METRIC_SAMPLES; j++) sum += inst_metrics[metric].samples[j];
for (uint64_t sample : inst_metrics[metric].samples) sum += sample;
return sum / STATS_METRIC_SAMPLES;
}
4 changes: 2 additions & 2 deletions src/storage/redis_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ std::vector<std::string> *WriteBatchLogData::GetArguments() { return &args_; }

std::string WriteBatchLogData::Encode() {
std::string ret = std::to_string(type_);
for (size_t i = 0; i < args_.size(); i++) {
ret += " " + args_[i];
for (const auto &arg : args_) {
ret += " " + arg;
}
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/redis_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ rocksdb::Status Set::Union(const std::vector<Slice> &keys, std::vector<std::stri

std::map<std::string, bool> union_members;
std::vector<std::string> target_members;
for (size_t i = 0; i < keys.size(); i++) {
auto s = Members(keys[i], &target_members);
for (const auto &key : keys) {
auto s = Members(key, &target_members);
if (!s.ok()) return s;
for (const auto &member : target_members) {
union_members[member] = true;
Expand Down
7 changes: 2 additions & 5 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ std::vector<rocksdb::Status> String::MGet(const std::vector<Slice> &keys, std::v
}
std::vector<Slice> slice_keys;
slice_keys.reserve(ns_keys.size());
// don't use range-based for loop here, coz the slice member
// would refer the address instead of copy the value, and use
// range-based for loop may cause all members refer to the same addr
for (size_t i = 0; i < ns_keys.size(); i++) {
slice_keys.emplace_back(ns_keys[i]);
for (const auto &ns_key : ns_keys) {
slice_keys.emplace_back(ns_key);
}
return getValues(slice_keys, values);
}
Expand Down

0 comments on commit 0c4d4b7

Please sign in to comment.