Skip to content

Commit

Permalink
msg/async/ProtocolV2: pass desc as std::string_view to write()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
MaxKellermann committed Oct 7, 2024
1 parent 7e5ebb7 commit 966920e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/msg/async/ProtocolV2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ CtPtr ProtocolV2::read(CONTINUATION_RXBPTR_TYPE<ProtocolV2> &next,
}

template <class F>
CtPtr ProtocolV2::write(const std::string &desc,
CtPtr ProtocolV2::write(std::string_view desc,
CONTINUATION_TYPE<ProtocolV2> &next,
F &frame) {
ceph::bufferlist bl;
Expand All @@ -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<ProtocolV2> &next,
ceph::bufferlist &buffer) {
if (unlikely(pre_auth.enabled)) {
Expand Down
4 changes: 2 additions & 2 deletions src/msg/async/ProtocolV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ class ProtocolV2 : public Protocol {
Ct<ProtocolV2> *read(CONTINUATION_RXBPTR_TYPE<ProtocolV2> &next,
rx_buffer_t&& buffer);
template <class F>
Ct<ProtocolV2> *write(const std::string &desc,
Ct<ProtocolV2> *write(std::string_view desc,
CONTINUATION_TYPE<ProtocolV2> &next,
F &frame);
Ct<ProtocolV2> *write(const std::string &desc,
Ct<ProtocolV2> *write(std::string_view desc,
CONTINUATION_TYPE<ProtocolV2> &next,
ceph::bufferlist &buffer);

Expand Down

0 comments on commit 966920e

Please sign in to comment.