Summary: Make folly `-Wpessimizing-move` clean:
Common errors:
```lang=bash
folly/io/test/NetworkBenchmark.cpp:71:30: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
unique_ptr<IOBuf> next = std::move(head->pop());
^
folly/io/IOBufQueue.cpp:153:28: error: moving a temporary object prevents copy elision [-Werror,-Wpessimizing-move]
appendToChain(head_, std::move(
^
folly/IPAddressV6.cpp:341:12: error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
return std::move(ip);
^
folly/IPAddressV6.cpp:341:12: note: remove std::move call here
return std::move(ip);
^~~~~~~~~~ ~
1 error generated.
```
Reviewed By: @fugalh, @meyering
Differential Revision:
D2526950
fb-gh-sync-id:
49291a8b49905eb9b2042d004830ff2f599dfbd3
buffer, INET6_ADDRSTRLEN,
nullptr, 0, NI_NUMERICHOST)) {
string ip(buffer);
- return std::move(ip);
+ return ip;
} else {
throw IPAddressFormatException("Invalid address with hex ",
"'", detail::Bytes::toHex(bytes(), 16), "'");
while (len != 0) {
if ((head_ == nullptr) || head_->prev()->isSharedOne() ||
(head_->prev()->tailroom() == 0)) {
- appendToChain(head_, std::move(
+ appendToChain(head_,
IOBuf::create(std::max(MIN_ALLOC_SIZE,
- std::min(len, MAX_ALLOC_SIZE)))),
+ std::min(len, MAX_ALLOC_SIZE))),
false);
}
IOBuf* last = head_->prev();
break;
}
}
- return std::move(result);
+ return result;
}
void IOBufQueue::trimStart(size_t amount) {
iovec op;
op.iov_base = const_cast<void*>(buf);
op.iov_len = bytes;
- writeImpl(callback, &op, 1, std::move(unique_ptr<IOBuf>()), flags);
+ writeImpl(callback, &op, 1, unique_ptr<IOBuf>(), flags);
}
void AsyncSocket::writev(WriteCallback* callback,
const iovec* vec,
size_t count,
WriteFlags flags) {
- writeImpl(callback, vec, count, std::move(unique_ptr<IOBuf>()), flags);
+ writeImpl(callback, vec, count, unique_ptr<IOBuf>(), flags);
}
void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr<IOBuf>&& buf,
unique_ptr<IOBuf> buf = IOBuf::create(len);
memcpy(buf->writableTail(), s, len);
buf->append(len);
- return std::move(buf);
+ return buf;
}
void checkConsistency(const IOBufQueue& queue) {
if (bufPool.size() > 0) {
unique_ptr<IOBuf> ret = std::move(bufPool.back());
bufPool.pop_back();
- return std::move(ret);
+ return ret;
} else {
unique_ptr<IOBuf> iobuf(IOBuf::create(buf_size));
iobuf->append(buf_size);
- return std::move(iobuf);
+ return iobuf;
}
}
inline void poolPutIOBuf(unique_ptr<IOBuf>&& buf) {
unique_ptr<IOBuf> head = std::move(buf);
while (head) {
- unique_ptr<IOBuf> next = std::move(head->pop());
+ unique_ptr<IOBuf> next = head->pop();
bufPool.push_back(std::move(head));
head = std::move(next);
}
BENCHMARK(poolBenchmark, iters) {
while (iters--) {
- unique_ptr<IOBuf> head = std::move(poolGetIOBuf());
+ unique_ptr<IOBuf> head = poolGetIOBuf();
for (size_t bufs = num_bufs; bufs > 1; bufs --) {
- unique_ptr<IOBuf> iobufNext = std::move(poolGetIOBuf());
+ unique_ptr<IOBuf> iobufNext = poolGetIOBuf();
head->prependChain(std::move(iobufNext));
}
// cleanup