]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
messages/MOSDPGNotify: add a ctor for moving pg_list
authorKefu Chai <kchai@redhat.com>
Tue, 26 Feb 2019 08:39:41 +0000 (16:39 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 16 Mar 2019 06:22:59 +0000 (14:22 +0800)
* use delegating constructor for less repeating
* add a constructor for movable pg_list parameter: less memcpy().

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/messages/MOSDPGNotify.h
src/osd/OSD.cc

index 4370eae3a5ab360d57caa351fad37a6a00fde7e7..6ec25020556a8ebc6cd558e6ced27ce6f6eb077b 100644 (file)
@@ -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<pair<pg_notify_t,PastIntervals> > pg_list;   // pgid -> version
+  using pg_list_t = std::vector<std::pair<pg_notify_t,PastIntervals>>;
+  pg_list_t pg_list;   // pgid -> version
 
  public:
   version_t get_epoch() const { return epoch; }
-  const vector<pair<pg_notify_t,PastIntervals> >& 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<pair<pg_notify_t,PastIntervals> >& 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:
index 49d307024276588dfcb50f51cb4816923c6d03f0..e511fa4e79b86a027aca20a51be6f384f9fd9deb 100644 (file)
@@ -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);