Skip to content

Commit 820294e

Browse files
hanidamlajmeta-codesync[bot]
authored andcommitted
folly::IOBuf::wrapIov refactor
Summary: was reviewing D85912162 (mvfst's noexcept version of IOBuf) and I suggested a small refactor for `::wrapIov` that folly could benefit from this elides one if/else branch Reviewed By: yfeldblum Differential Revision: D86323278 fbshipit-source-id: 6feafdb8479b948ec200c5fc2ededa95e863c6c8
1 parent 3d68dbb commit 820294e

1 file changed

Lines changed: 3 additions & 10 deletions

File tree

third-party/folly/src/folly/io/IOBuf.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,23 +1421,16 @@ void IOBuf::appendToIov(folly::fbvector<struct iovec>* iov) const {
14211421
}
14221422

14231423
unique_ptr<IOBuf> IOBuf::wrapIov(const iovec* vec, size_t count) {
1424-
unique_ptr<IOBuf> result = nullptr;
1424+
IOBuf result{};
14251425
for (size_t i = 0; i < count; ++i) {
14261426
size_t len = vec[i].iov_len;
14271427
void* data = vec[i].iov_base;
14281428
if (len > 0) {
14291429
auto buf = wrapBuffer(data, len);
1430-
if (!result) {
1431-
result = std::move(buf);
1432-
} else {
1433-
result->appendToChain(std::move(buf));
1434-
}
1430+
result.appendToChain(std::move(buf));
14351431
}
14361432
}
1437-
if (FOLLY_UNLIKELY(result == nullptr)) {
1438-
return create(0);
1439-
}
1440-
return result;
1433+
return result.isChained() ? result.pop() : create(0);
14411434
}
14421435

14431436
std::unique_ptr<IOBuf> IOBuf::takeOwnershipIov(

0 commit comments

Comments
 (0)