Skip to content

Commit

Permalink
IOBuf moveToFbString().toStdString() -> to<std::string>()
Browse files Browse the repository at this point in the history
Summary: Constructing an `fbstring` from an `IOBuf` and then converting that to `std::string` is inefficient: if the `IOBuf` is chained, that can end up copying the data twice. `to<std::string>()` does exactly one copy.

Reviewed By: Orvid

Differential Revision: D58380666

fbshipit-source-id: c656473078149d30ed8c375e4b423ab775910fab
  • Loading branch information
ot authored and facebook-github-bot committed Jun 10, 2024
1 parent 4036cae commit e138798
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions wangle/channel/broadcast/test/BroadcastHandlerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST_F(BroadcastHandlerTest, SubscribeUnsubscribe) {
auto buf = q.move();
if (buf) {
buf->coalesce();
data = buf->moveToFbString().toStdString();
data = buf->to<std::string>();
return true;
}
return false;
Expand Down Expand Up @@ -153,7 +153,7 @@ TEST_F(BroadcastHandlerTest, BufferedRead) {
}
auto buf = bufQueue.move();
buf->coalesce();
data = buf->moveToFbString().toStdString();
data = buf->to<std::string>();
return true;
}));

Expand Down Expand Up @@ -222,7 +222,7 @@ TEST_F(BroadcastHandlerTest, OnCompleted) {
auto buf = q.move();
if (buf) {
buf->coalesce();
data = buf->moveToFbString().toStdString();
data = buf->to<std::string>();
return true;
}
return false;
Expand Down Expand Up @@ -277,7 +277,7 @@ TEST_F(BroadcastHandlerTest, OnError) {
auto buf = q.move();
if (buf) {
buf->coalesce();
data = buf->moveToFbString().toStdString();
data = buf->to<std::string>();
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion wangle/example/broadcast/BroadcastProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ByteToStringDecoder : public ByteToMessageDecoder<std::string> {
bool decode(Context*, IOBufQueue& buf, std::string& result, size_t&)
override {
if (buf.chainLength() > 0) {
result = buf.move()->moveToFbString().toStdString();
result = buf.move()->to<std::string>();
return true;
}
return false;
Expand Down

0 comments on commit e138798

Please sign in to comment.