]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/async/AsyncConnection: do not wrap writeCallback in `std::optional`
authorMax Kellermann <max.kellermann@ionos.com>
Tue, 8 Oct 2024 12:50:02 +0000 (14:50 +0200)
committerMax Kellermann <max.kellermann@ionos.com>
Wed, 9 Oct 2024 21:15:15 +0000 (23:15 +0200)
Since `std::function` is nullable and as an `operator bool()`, we can
easily eliminate the `std::optional` overhead.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
src/msg/async/AsyncConnection.cc
src/msg/async/AsyncConnection.h
src/msg/async/ProtocolV1.cc
src/msg/async/ProtocolV2.cc

index 683be086efadad84a9221d45e31ba2dbed2bdc43..649977e5b9697fd7861f081a3f2bd65df1db49d2 100644 (file)
@@ -621,7 +621,7 @@ void AsyncConnection::fault()
 }
 
 void AsyncConnection::_stop() {
-  writeCallback.reset();
+  writeCallback = {};
   dispatch_queue->discard_queue(conn_id);
   async_msgr->unregister_conn(this);
   worker->release_worker();
@@ -737,8 +737,7 @@ void AsyncConnection::handle_write_callback() {
   recv_start_time = ceph::mono_clock::now();
   write_lock.lock();
   if (writeCallback) {
-    auto callback = *writeCallback;
-    writeCallback.reset();
+    auto callback = std::move(writeCallback);
     write_lock.unlock();
     callback(0);
     return;
index 78a590f8ca393eaef103cf4303d19373a2febfce..a4f18e2c4fb5702d0c60abecf2364de0a7c39243 100644 (file)
@@ -223,7 +223,7 @@ private:
 
   std::unique_ptr<Protocol> protocol;
 
-  std::optional<std::function<void(ssize_t)>> writeCallback;
+  std::function<void(ssize_t)> writeCallback;
   std::function<void(char *, ssize_t)> readCallback;
   std::optional<unsigned> pendingReadLen;
   char *read_buffer;
index cecf81498c7017115e7094bd18cdbfdd8f8938e7..a53f6389c3101da81541ea93fbaf69802e5da269 100644 (file)
@@ -1294,7 +1294,7 @@ void ProtocolV1::reset_recv_state()
 
   // clean read and write callbacks
   connection->pendingReadLen.reset();
-  connection->writeCallback.reset();
+  connection->writeCallback = {};
 
   if (state > THROTTLE_MESSAGE && state <= READ_FOOTER_AND_DISPATCH &&
       connection->policy.throttler_messages) {
index 11b3885a2240264549244dc7350e9b4d1bc8488f..79fdf6c30a3649e0a59f43b4ba8e7bc06cda6d30 100644 (file)
@@ -266,7 +266,7 @@ void ProtocolV2::reset_recv_state() {
 
   // clean read and write callbacks
   connection->pendingReadLen.reset();
-  connection->writeCallback.reset();
+  connection->writeCallback = {};
 
   next_tag = static_cast<Tag>(0);