Skip to content

Commit 966920e

Browse files
committed
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 <[email protected]>
1 parent 7e5ebb7 commit 966920e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/msg/async/ProtocolV2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ CtPtr ProtocolV2::read(CONTINUATION_RXBPTR_TYPE<ProtocolV2> &next,
796796
}
797797

798798
template <class F>
799-
CtPtr ProtocolV2::write(const std::string &desc,
799+
CtPtr ProtocolV2::write(std::string_view desc,
800800
CONTINUATION_TYPE<ProtocolV2> &next,
801801
F &frame) {
802802
ceph::bufferlist bl;
@@ -812,7 +812,7 @@ CtPtr ProtocolV2::write(const std::string &desc,
812812
return write(desc, next, bl);
813813
}
814814

815-
CtPtr ProtocolV2::write(const std::string &desc,
815+
CtPtr ProtocolV2::write(std::string_view desc,
816816
CONTINUATION_TYPE<ProtocolV2> &next,
817817
ceph::bufferlist &buffer) {
818818
if (unlikely(pre_auth.enabled)) {

src/msg/async/ProtocolV2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ class ProtocolV2 : public Protocol {
130130
Ct<ProtocolV2> *read(CONTINUATION_RXBPTR_TYPE<ProtocolV2> &next,
131131
rx_buffer_t&& buffer);
132132
template <class F>
133-
Ct<ProtocolV2> *write(const std::string &desc,
133+
Ct<ProtocolV2> *write(std::string_view desc,
134134
CONTINUATION_TYPE<ProtocolV2> &next,
135135
F &frame);
136-
Ct<ProtocolV2> *write(const std::string &desc,
136+
Ct<ProtocolV2> *write(std::string_view desc,
137137
CONTINUATION_TYPE<ProtocolV2> &next,
138138
ceph::bufferlist &buffer);
139139

0 commit comments

Comments
 (0)