From 268ad74e4ea879f7a367b51ea4231cb41dd0ed45 Mon Sep 17 00:00:00 2001 From: Michal Jarzabek Date: Wed, 5 Oct 2016 19:53:50 +0100 Subject: [PATCH] mds/SessionMap.cc: remove unneeded use of count Signed-off-by: Michal Jarzabek --- src/mds/SessionMap.cc | 47 +++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index 9c536e1a020c..52d6be0f483f 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -225,9 +225,11 @@ void SessionMap::_load_finish( for (ceph::unordered_map::iterator i = session_map.begin(); i != session_map.end(); ++i) { Session *s = i->second; - if (by_state.count(s->get_state()) == 0) - by_state[s->get_state()] = new xlist; - by_state[s->get_state()]->push_back(&s->item_session_list); + auto by_state_entry = by_state.find(s->get_state()); + if (by_state_entry == by_state.end()) + by_state_entry = by_state.emplace(s->get_state(), + new xlist).first; + by_state_entry->second->push_back(&s->item_session_list); } // Population is complete. Trigger load waiters. @@ -442,18 +444,21 @@ void SessionMap::decode_legacy(bufferlist::iterator &p) for (ceph::unordered_map::iterator i = session_map.begin(); i != session_map.end(); ++i) { Session *s = i->second; - if (by_state.count(s->get_state()) == 0) - by_state[s->get_state()] = new xlist; - by_state[s->get_state()]->push_back(&s->item_session_list); + auto by_state_entry = by_state.find(s->get_state()); + if (by_state_entry == by_state.end()) + by_state_entry = by_state.emplace(s->get_state(), + new xlist).first; + by_state_entry->second->push_back(&s->item_session_list); } } uint64_t SessionMap::set_state(Session *session, int s) { if (session->state != s) { session->set_state(s); - if (by_state.count(s) == 0) - by_state[s] = new xlist; - by_state[s]->push_back(&session->item_session_list); + auto by_state_entry = by_state.find(s); + if (by_state_entry == by_state.end()) + by_state_entry = by_state.emplace(s, new xlist).first; + by_state_entry->second->push_back(&session->item_session_list); } return session->get_state_seq(); } @@ -565,9 +570,10 @@ void SessionMap::add_session(Session *s) assert(session_map.count(s->info.inst.name) == 0); session_map[s->info.inst.name] = s; - if (by_state.count(s->state) == 0) - by_state[s->state] = new xlist; - by_state[s->state]->push_back(&s->item_session_list); + auto by_state_entry = by_state.find(s->state); + if (by_state_entry == by_state.end()) + by_state_entry = by_state.emplace(s->state, new xlist).first; + by_state_entry->second->push_back(&s->item_session_list); s->get(); logger->set(l_mdssm_session_count, session_map.size()); @@ -581,9 +587,7 @@ void SessionMap::remove_session(Session *s) s->trim_completed_requests(0); s->item_session_list.remove_myself(); session_map.erase(s->info.inst.name); - if (dirty_sessions.count(s->info.inst.name)) { - dirty_sessions.erase(s->info.inst.name); - } + dirty_sessions.erase(s->info.inst.name); null_sessions.insert(s->info.inst.name); s->put(); @@ -598,9 +602,11 @@ void SessionMap::touch_session(Session *session) // Move to the back of the session list for this state (should // already be on a list courtesy of add_session and set_state) assert(session->item_session_list.is_on_list()); - if (by_state.count(session->state) == 0) - by_state[session->state] = new xlist; - by_state[session->state]->push_back(&session->item_session_list); + auto by_state_entry = by_state.find(session->state); + if (by_state_entry == by_state.end()) + by_state_entry = by_state.emplace(session->state, + new xlist).first; + by_state_entry->second->push_back(&session->item_session_list); session->last_cap_renew = ceph_clock_now(g_ceph_context); } @@ -833,9 +839,10 @@ void Session::set_client_metadata(map const &meta) */ void Session::_update_human_name() { - if (info.client_metadata.count("hostname")) { + auto info_client_metadata_entry = info.client_metadata.find("hostname"); + if (info_client_metadata_entry != info.client_metadata.end()) { // Happy path, refer to clients by hostname - human_name = info.client_metadata["hostname"]; + human_name = info_client_metadata_entry->second; if (!info.auth_name.has_default_id()) { // When a non-default entity ID is set by the user, assume they // would like to see it in references to the client, if it's -- 2.47.3