Skip to content

Commit

Permalink
use the const reference for avoiding copy (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackwener authored Jul 3, 2022
1 parent 09921ff commit a942549
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ Status Cluster::ParseClusterNodes(const std::string &nodes_str, ClusterNodes *no
nodes->clear();

// Parse all nodes
for (const auto& node_str : nodes_info) {
for (const auto &node_str : nodes_info) {
std::vector<std::string> fields = Util::Split(node_str, " ");
if (fields.size() < 5) {
return Status(Status::ClusterInvalidInfo, "Invalid cluster nodes info");
Expand Down
4 changes: 2 additions & 2 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void Config::initFieldValidator() {
return Status::OK();
}},
};
for (const auto& iter : validators) {
for (const auto &iter : validators) {
auto field_iter = fields_.find(iter.first);
if (field_iter != fields_.end()) {
field_iter->second->validate = iter.second;
Expand Down Expand Up @@ -479,7 +479,7 @@ void Config::initFieldCallback() {
{"rocksdb.level0_stop_writes_trigger", set_cf_option_cb},
{"rocksdb.level0_file_num_compaction_trigger", set_cf_option_cb}
};
for (const auto& iter : callbacks) {
for (const auto &iter : callbacks) {
auto field_iter = fields_.find(iter.first);
if (field_iter != fields_.end()) {
field_iter->second->callback = iter.second;
Expand Down
6 changes: 3 additions & 3 deletions src/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Status Server::Start() {
}
}

for (const auto& worker : worker_threads_) {
for (const auto &worker : worker_threads_) {
worker->Start();
}
task_runner_.Start();
Expand Down Expand Up @@ -171,7 +171,7 @@ Status Server::Start() {
void Server::Stop() {
stop_ = true;
if (replication_thread_) replication_thread_->Stop();
for (const auto& worker : worker_threads_) {
for (const auto &worker : worker_threads_) {
worker->Stop();
}
DisconnectSlaves();
Expand All @@ -180,7 +180,7 @@ void Server::Stop() {
}

void Server::Join() {
for (const auto& worker : worker_threads_) {
for (const auto &worker : worker_threads_) {
worker->Join();
}
task_runner_.Join();
Expand Down
2 changes: 1 addition & 1 deletion tests/cppunit/rwlock_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
TEST(LockManager, LockKey) {
LockManager locks(8);
std::vector<rocksdb::Slice> keys = {"abc", "123", "456", "abc", "123"};
for (const auto key : keys) {
for (const auto &key : keys) {
locks.Lock(key);
locks.UnLock(key);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cppunit/t_string_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST_F(RedisStringTest, MGetAndMSet) {
string->MSet(pairs_);
std::vector<Slice> keys;
std::vector<std::string> values;
for (const auto pair : pairs_) {
for (const auto &pair : pairs_) {
keys.emplace_back(pair.key);
}
string->MGet(keys, &values);
Expand Down Expand Up @@ -178,7 +178,7 @@ TEST_F(RedisStringTest, MSetNX) {
EXPECT_EQ(1, ret);
std::vector<Slice> keys;
std::vector<std::string> values;
for (const auto pair : pairs_) {
for (const auto &pair : pairs_) {
keys.emplace_back(pair.key);
}
string->MGet(keys, &values);
Expand Down

0 comments on commit a942549

Please sign in to comment.