From 966920e063cc1fa276fbc09798779d71be51947d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 3 Oct 2024 17:21:23 +0200 Subject: [PATCH] msg/async/ProtocolV2: pass `desc` as `std::string_view` to write() All callers really pass a C string literal, and declaring a `std::string` parameter will implicitly create two `std::string` instances: one on the caller's stack, and another one inside write() as parameter to the continuation lambda. This causes considerable and unnecessary overhead. Signed-off-by: Max Kellermann --- src/msg/async/ProtocolV2.cc | 4 ++-- src/msg/async/ProtocolV2.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index 6d44d6c783f44..c4cfa76d16f15 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -796,7 +796,7 @@ CtPtr ProtocolV2::read(CONTINUATION_RXBPTR_TYPE &next, } template -CtPtr ProtocolV2::write(const std::string &desc, +CtPtr ProtocolV2::write(std::string_view desc, CONTINUATION_TYPE &next, F &frame) { ceph::bufferlist bl; @@ -812,7 +812,7 @@ CtPtr ProtocolV2::write(const std::string &desc, return write(desc, next, bl); } -CtPtr ProtocolV2::write(const std::string &desc, +CtPtr ProtocolV2::write(std::string_view desc, CONTINUATION_TYPE &next, ceph::bufferlist &buffer) { if (unlikely(pre_auth.enabled)) { diff --git a/src/msg/async/ProtocolV2.h b/src/msg/async/ProtocolV2.h index 6441866fea4c3..918003a21ced7 100644 --- a/src/msg/async/ProtocolV2.h +++ b/src/msg/async/ProtocolV2.h @@ -130,10 +130,10 @@ class ProtocolV2 : public Protocol { Ct *read(CONTINUATION_RXBPTR_TYPE &next, rx_buffer_t&& buffer); template - Ct *write(const std::string &desc, + Ct *write(std::string_view desc, CONTINUATION_TYPE &next, F &frame); - Ct *write(const std::string &desc, + Ct *write(std::string_view desc, CONTINUATION_TYPE &next, ceph::bufferlist &buffer);