diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 210f7755090..a7fc0940767 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -111,11 +111,9 @@ PyObject *ActivePyModules::list_servers_python() (const std::map &all) { PyEval_RestoreThread(tstate); - for (const auto &i : all) { - const auto &hostname = i.first; - + for (const auto &[hostname, daemon_state] : all) { f.open_object_section("server"); - dump_server(hostname, i.second, &f); + dump_server(hostname, daemon_state, &f); f.close_section(); } }); @@ -136,8 +134,8 @@ PyObject *ActivePyModules::get_metadata_python( std::lock_guard l(metadata->lock); PyFormatter f; f.dump_string("hostname", metadata->hostname); - for (const auto &i : metadata->metadata) { - f.dump_string(i.first.c_str(), i.second); + for (const auto &[key, val] : metadata->metadata) { + f.dump_string(key, val); } return f.get(); @@ -155,8 +153,8 @@ PyObject *ActivePyModules::get_daemon_status_python( std::lock_guard l(metadata->lock); PyFormatter f; - for (const auto &i : metadata->service_status) { - f.dump_string(i.first.c_str(), i.second); + for (const auto &[daemon, status] : metadata->service_status) { + f.dump_string(daemon, status); } return f.get(); } diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 87f820bffb7..07d58541799 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -216,8 +216,8 @@ DaemonStateCollection DaemonStateIndex::get_by_server( { std::shared_lock l{lock}; - if (by_server.count(hostname)) { - return by_server.at(hostname); + if (auto found = by_server.find(hostname); found != by_server.end()) { + return found->second; } else { return {}; } diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index 24fb4e7dc81..781017a2689 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -100,9 +100,8 @@ void MetadataUpdate::finish(int r) } } - DaemonStatePtr state; if (daemon_state.exists(key)) { - state = daemon_state.get(key); + DaemonStatePtr state = daemon_state.get(key); state->hostname = daemon_meta.at("hostname").get_str(); if (key.type == "mds" || key.type == "mgr" || key.type == "mon") { @@ -112,13 +111,12 @@ void MetadataUpdate::finish(int r) } daemon_meta.erase("hostname"); map m; - for (const auto &i : daemon_meta) { - m[i.first] = i.second.get_str(); + for (const auto &[key, val] : daemon_meta) { + m.emplace(key, val.get_str()); } - daemon_state.update_metadata(state, m); } else { - state = std::make_shared(daemon_state.types); + auto state = std::make_shared(daemon_state.types); state->key = key; state->hostname = daemon_meta.at("hostname").get_str(); @@ -130,8 +128,8 @@ void MetadataUpdate::finish(int r) daemon_meta.erase("hostname"); map m; - for (const auto &i : daemon_meta) { - m[i.first] = i.second.get_str(); + for (const auto &[key, val] : daemon_meta) { + m.emplace(key, val.get_str()); } state->set_metadata(m); @@ -371,8 +369,8 @@ void Mgr::load_all_metadata() daemon_meta.erase("name"); daemon_meta.erase("hostname"); - for (const auto &i : daemon_meta) { - dm->metadata[i.first] = i.second.get_str(); + for (const auto &[key, val] : daemon_meta) { + dm->metadata.emplace(key, val.get_str()); } daemon_state.insert(dm); @@ -394,8 +392,8 @@ void Mgr::load_all_metadata() daemon_meta.erase("hostname"); map m; - for (const auto &i : daemon_meta) { - m[i.first] = i.second.get_str(); + for (const auto &[key, val] : daemon_meta) { + m.emplace(key, val.get_str()); } dm->set_metadata(m);