Skip to content

Commit c72dae9

Browse files
committed
msg/async/AsyncConnection: do not wrap writeCallback in std::optional
Since `std::function` is nullable and as an `operator bool()`, we can easily eliminate the `std::optional` overhead. Signed-off-by: Max Kellermann <[email protected]>
1 parent 10a9914 commit c72dae9

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

src/msg/async/AsyncConnection.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ void AsyncConnection::fault()
621621
}
622622

623623
void AsyncConnection::_stop() {
624-
writeCallback.reset();
624+
writeCallback = {};
625625
dispatch_queue->discard_queue(conn_id);
626626
async_msgr->unregister_conn(this);
627627
worker->release_worker();
@@ -737,8 +737,7 @@ void AsyncConnection::handle_write_callback() {
737737
recv_start_time = ceph::mono_clock::now();
738738
write_lock.lock();
739739
if (writeCallback) {
740-
auto callback = *writeCallback;
741-
writeCallback.reset();
740+
auto callback = std::move(writeCallback);
742741
write_lock.unlock();
743742
callback(0);
744743
return;

src/msg/async/AsyncConnection.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class AsyncConnection : public Connection {
223223

224224
std::unique_ptr<Protocol> protocol;
225225

226-
std::optional<std::function<void(ssize_t)>> writeCallback;
226+
std::function<void(ssize_t)> writeCallback;
227227
std::function<void(char *, ssize_t)> readCallback;
228228
std::optional<unsigned> pendingReadLen;
229229
char *read_buffer;

src/msg/async/ProtocolV1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ void ProtocolV1::reset_recv_state()
12941294

12951295
// clean read and write callbacks
12961296
connection->pendingReadLen.reset();
1297-
connection->writeCallback.reset();
1297+
connection->writeCallback = {};
12981298

12991299
if (state > THROTTLE_MESSAGE && state <= READ_FOOTER_AND_DISPATCH &&
13001300
connection->policy.throttler_messages) {

src/msg/async/ProtocolV2.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void ProtocolV2::reset_recv_state() {
266266

267267
// clean read and write callbacks
268268
connection->pendingReadLen.reset();
269-
connection->writeCallback.reset();
269+
connection->writeCallback = {};
270270

271271
next_tag = static_cast<Tag>(0);
272272

0 commit comments

Comments
 (0)