Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance-inefficient-vector-operation warning reported by clang-tidy #1115

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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, 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 @@ -4275,6 +4277,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 @@ -4558,6 +4561,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