From: Igor Sugak Date: Tue, 13 Oct 2015 00:15:20 +0000 (-0700) Subject: folly: fix clang -Wpessimizing-move X-Git-Tag: deprecate-dynamic-initializer~339 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=a2bab0fb305e8f3c073316c3c2575630a5b9ac31 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 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 --- diff --git a/folly/IPAddressV6.cpp b/folly/IPAddressV6.cpp index 49a1b23c..f88d1b02 100644 --- a/folly/IPAddressV6.cpp +++ b/folly/IPAddressV6.cpp @@ -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), "'"); diff --git a/folly/io/IOBufQueue.cpp b/folly/io/IOBufQueue.cpp index 37e0635e..467bac68 100644 --- a/folly/io/IOBufQueue.cpp +++ b/folly/io/IOBufQueue.cpp @@ -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) { diff --git a/folly/io/async/AsyncSocket.cpp b/folly/io/async/AsyncSocket.cpp index 6adeb940..9320d0f9 100644 --- a/folly/io/async/AsyncSocket.cpp +++ b/folly/io/async/AsyncSocket.cpp @@ -611,14 +611,14 @@ void AsyncSocket::write(WriteCallback* callback, iovec op; op.iov_base = const_cast(buf); op.iov_len = bytes; - writeImpl(callback, &op, 1, std::move(unique_ptr()), flags); + writeImpl(callback, &op, 1, unique_ptr(), flags); } void AsyncSocket::writev(WriteCallback* callback, const iovec* vec, size_t count, WriteFlags flags) { - writeImpl(callback, vec, count, std::move(unique_ptr()), flags); + writeImpl(callback, vec, count, unique_ptr(), flags); } void AsyncSocket::writeChain(WriteCallback* callback, unique_ptr&& buf, diff --git a/folly/io/test/IOBufQueueTest.cpp b/folly/io/test/IOBufQueueTest.cpp index 8afed780..090a2d9c 100644 --- a/folly/io/test/IOBufQueueTest.cpp +++ b/folly/io/test/IOBufQueueTest.cpp @@ -49,7 +49,7 @@ stringToIOBuf(const char* s, uint32_t len) { unique_ptr buf = IOBuf::create(len); memcpy(buf->writableTail(), s, len); buf->append(len); - return std::move(buf); + return buf; } void checkConsistency(const IOBufQueue& queue) { diff --git a/folly/io/test/NetworkBenchmark.cpp b/folly/io/test/NetworkBenchmark.cpp index 1b86770d..ad4de0e0 100644 --- a/folly/io/test/NetworkBenchmark.cpp +++ b/folly/io/test/NetworkBenchmark.cpp @@ -57,18 +57,18 @@ inline unique_ptr poolGetIOBuf() { if (bufPool.size() > 0) { unique_ptr ret = std::move(bufPool.back()); bufPool.pop_back(); - return std::move(ret); + return ret; } else { unique_ptr iobuf(IOBuf::create(buf_size)); iobuf->append(buf_size); - return std::move(iobuf); + return iobuf; } } inline void poolPutIOBuf(unique_ptr&& buf) { unique_ptr head = std::move(buf); while (head) { - unique_ptr next = std::move(head->pop()); + unique_ptr next = head->pop(); bufPool.push_back(std::move(head)); head = std::move(next); } @@ -76,9 +76,9 @@ inline void poolPutIOBuf(unique_ptr&& buf) { BENCHMARK(poolBenchmark, iters) { while (iters--) { - unique_ptr head = std::move(poolGetIOBuf()); + unique_ptr head = poolGetIOBuf(); for (size_t bufs = num_bufs; bufs > 1; bufs --) { - unique_ptr iobufNext = std::move(poolGetIOBuf()); + unique_ptr iobufNext = poolGetIOBuf(); head->prependChain(std::move(iobufNext)); } // cleanup