]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/HeartbeatMap: pass name as rvalue reference
authorMax Kellermann <max.kellermann@ionos.com>
Fri, 4 Oct 2024 10:54:26 +0000 (12:54 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Wed, 9 Oct 2024 20:39:56 +0000 (22:39 +0200)
This eliminates one temporary copy per call.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/common/HeartbeatMap.cc
src/common/HeartbeatMap.h

index 54442709229550cac3f9527494ef76c4e7f192de..246cec9460b1a0a7c7844bc3c452d5738207c4f0 100644 (file)
@@ -43,11 +43,11 @@ HeartbeatMap::~HeartbeatMap()
   ceph_assert(m_workers.empty());
 }
 
-heartbeat_handle_d *HeartbeatMap::add_worker(const string& name, pthread_t thread_id)
+heartbeat_handle_d *HeartbeatMap::add_worker(string&& name, pthread_t thread_id)
 {
   std::unique_lock locker{m_rwlock};
   ldout(m_cct, 10) << "add_worker '" << name << "'" << dendl;
-  heartbeat_handle_d *h = new heartbeat_handle_d(name);
+  heartbeat_handle_d *h = new heartbeat_handle_d(std::move(name));
   ANNOTATE_BENIGN_RACE_SIZED(&h->timeout, sizeof(h->timeout),
                              "heartbeat_handle_d timeout");
   ANNOTATE_BENIGN_RACE_SIZED(&h->suicide_timeout, sizeof(h->suicide_timeout),
index 6f486b21ca864fc07a356c2f7fa37ccdb929831d..401042cc271742dfa4e20ed82fe450f4c397a966 100644 (file)
@@ -48,15 +48,15 @@ struct heartbeat_handle_d {
   ceph::timespan suicide_grace = ceph::timespan::zero();
   std::list<heartbeat_handle_d*>::iterator list_item;
 
-  explicit heartbeat_handle_d(const std::string& n)
-    : name(n)
+  explicit heartbeat_handle_d(std::string&& n)
+    : name(std::move(n))
   { }
 };
 
 class HeartbeatMap {
  public:
   // register/unregister
-  heartbeat_handle_d *add_worker(const std::string& name, pthread_t thread_id);
+  heartbeat_handle_d *add_worker(std::string&& name, pthread_t thread_id);
   void remove_worker(const heartbeat_handle_d *h);
 
   // reset the timeout so that it expects another touch within grace amount of time