Skip to content

Commit

Permalink
Fix performance-inefficient-vector-operation warning reported by clan…
Browse files Browse the repository at this point in the history
…g-tidy (#1115)

Co-authored-by: Twice <[email protected]>
  • Loading branch information
tanruixiang and PragmaTwice authored Nov 15, 2022
1 parent 9bebd6b commit 4cd34dc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
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
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

CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
Expand Down
4 changes: 4 additions & 0 deletions src/commands/redis_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@ class CommandHKeys : public Commander {
return Status(Status::RedisExecErr, s.ToString());
}
std::vector<std::string> keys;
keys.reserve(field_values.size());
for (const auto &fv : field_values) {
keys.emplace_back(fv.field);
}
Expand All @@ -1476,6 +1477,7 @@ class CommandHVals : public Commander {
return Status(Status::RedisExecErr, s.ToString());
}
std::vector<std::string> values;
values.reserve(field_values.size());
for (const auto &p : field_values) {
values.emplace_back(p.value);
}
Expand Down Expand Up @@ -4277,6 +4279,7 @@ class CommandCommand : public Commander {
return Status::OK();
}
std::vector<std::string> keys;
keys.reserve(keys_indexes.size());
for (const auto &key_index : keys_indexes) {
keys.emplace_back(args_[key_index + 2]);
}
Expand Down Expand Up @@ -4560,6 +4563,7 @@ class CommandZScan : public CommandSubkeyScanBase {
return Status(Status::RedisExecErr, s.ToString());
}
std::vector<std::string> score_strings;
score_strings.reserve(scores.size());
for (const auto &score : scores) {
score_strings.emplace_back(Util::Float2String(score));
}
Expand Down
1 change: 1 addition & 0 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ rocksdb::Status String::MSetNX(const std::vector<StringPair> &pairs, int ttl, in

int exists;
std::vector<Slice> keys;
keys.reserve(pairs.size());
for (StringPair pair : pairs) {
keys.emplace_back(pair.key);
}
Expand Down
1 change: 1 addition & 0 deletions src/types/redis_zset.cc
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ rocksdb::Status ZSet::UnionStore(const Slice &dst, const std::vector<KeyWeight>
}
if (!dst_zset.empty()) {
std::vector<MemberScore> mscores;
mscores.reserve(dst_zset.size());
for (const auto &iter : dst_zset) {
mscores.emplace_back(MemberScore{iter.first, iter.second});
}
Expand Down

0 comments on commit 4cd34dc

Please sign in to comment.