From b99d2d85fe96ab25a03f708c612a1c867e775dc7 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 26 Feb 2019 16:39:41 +0800 Subject: [PATCH] messages/MOSDPGNotify: add a ctor for moving pg_list * use delegating constructor for less repeating * add a constructor for movable pg_list parameter: less memcpy(). Signed-off-by: Kefu Chai --- src/messages/MOSDPGNotify.h | 16 ++++++++-------- src/osd/OSD.cc | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/messages/MOSDPGNotify.h b/src/messages/MOSDPGNotify.h index 4370eae3a5ab3..6ec25020556a8 100644 --- a/src/messages/MOSDPGNotify.h +++ b/src/messages/MOSDPGNotify.h @@ -35,22 +35,22 @@ private: /// the current epoch if this is not being sent in response to a /// query. This allows the recipient to disregard responses to old /// queries. - vector > pg_list; // pgid -> version + using pg_list_t = std::vector>; + pg_list_t pg_list; // pgid -> version public: version_t get_epoch() const { return epoch; } - const vector >& get_pg_list() const { + const pg_list_t& get_pg_list() const { return pg_list; } MOSDPGNotify() - : MessageInstance(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION) { - set_priority(CEPH_MSG_PRIO_HIGH); - } - MOSDPGNotify(epoch_t e, vector >& l) + : MOSDPGNotify(0, {}) + {} + MOSDPGNotify(epoch_t e, pg_list_t&& l) : MessageInstance(MSG_OSD_PG_NOTIFY, HEAD_VERSION, COMPAT_VERSION), - epoch(e) { - pg_list.swap(l); + epoch(e), + pg_list(std::move(l)) { set_priority(CEPH_MSG_PRIO_HIGH); } private: diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 49d3070242765..e511fa4e79b86 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -9184,7 +9184,7 @@ void OSD::do_notifies( dout(7) << __func__ << " osd." << it->first << " on " << it->second.size() << " PGs" << dendl; MOSDPGNotify *m = new MOSDPGNotify(curmap->get_epoch(), - it->second); + std::move(it->second)); con->send_message(m); } } @@ -9478,7 +9478,7 @@ void OSD::handle_pg_query_nopg(const MQuery& q) osdmap->get_epoch(), empty), PastIntervals())); - m = new MOSDPGNotify(osdmap->get_epoch(), ls); + m = new MOSDPGNotify(osdmap->get_epoch(), std::move(ls)); } service.share_map_peer(q.from.osd, con.get(), osdmap); con->send_message(m); -- 2.39.5