From: Max Kellermann Date: Fri, 4 Oct 2024 10:54:26 +0000 (+0200) Subject: common/HeartbeatMap: pass name as rvalue reference X-Git-Tag: v20.0.0~791^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2e2bcd5518afd99d18d455be42985e78a8bd4407;p=ceph.git common/HeartbeatMap: pass name as rvalue reference This eliminates one temporary copy per call. Signed-off-by: Max Kellermann --- diff --git a/src/common/HeartbeatMap.cc b/src/common/HeartbeatMap.cc index 544427092295..246cec9460b1 100644 --- a/src/common/HeartbeatMap.cc +++ b/src/common/HeartbeatMap.cc @@ -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), diff --git a/src/common/HeartbeatMap.h b/src/common/HeartbeatMap.h index 6f486b21ca86..401042cc2717 100644 --- a/src/common/HeartbeatMap.h +++ b/src/common/HeartbeatMap.h @@ -48,15 +48,15 @@ struct heartbeat_handle_d { ceph::timespan suicide_grace = ceph::timespan::zero(); std::list::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