Commit a2bab0fb authored by Igor Sugak's avatar Igor Sugak Committed by facebook-github-bot-4

folly: fix clang -Wpessimizing-move

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
parent 09417cff
......@@ -338,7 +338,7 @@ string IPAddressV6::str() const {
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), "'");
......
......@@ -150,9 +150,9 @@ IOBufQueue::append(const void* buf, size_t len) {
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();
......@@ -209,7 +209,7 @@ IOBufQueue::split(size_t n) {
break;
}
}
return std::move(result);
return result;
}
void IOBufQueue::trimStart(size_t amount) {
......
......@@ -611,14 +611,14 @@ void AsyncSocket::write(WriteCallback* callback,
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,
......
......@@ -49,7 +49,7 @@ stringToIOBuf(const char* s, uint32_t len) {
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) {
......
......@@ -57,18 +57,18 @@ inline unique_ptr<IOBuf> poolGetIOBuf() {
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);
}
......@@ -76,9 +76,9 @@ inline void poolPutIOBuf(unique_ptr<IOBuf>&& buf) {
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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment