folly: fix clang -Wpessimizing-move
authorIgor Sugak <sugak@fb.com>
Tue, 13 Oct 2015 00:15:20 +0000 (17:15 -0700)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Tue, 13 Oct 2015 05:21:05 +0000 (22:21 -0700)
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

folly/IPAddressV6.cpp
folly/io/IOBufQueue.cpp
folly/io/async/AsyncSocket.cpp
folly/io/test/IOBufQueueTest.cpp
folly/io/test/NetworkBenchmark.cpp

index 49a1b23cd8ce12c562cb3834bf30b05dda97d0f5..f88d1b02891867a0c85d7ccb093c9db8b0135d1b 100644 (file)
@@ -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), "'");
index 37e0635e505c59344e267c1c62b96f01af0b198e..467bac68e0901cc47b1c827e0d87e9f7dda1c813 100644 (file)
@@ -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) {
index 6adeb940196546a95ec5b91ac6a9b3b1a29efa54..9320d0f9b3930dd671e597ca4609714cd7e364f7 100644 (file)
@@ -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,
index 8afed780a683cc2fe0822a8b5a7c13a601b3e5e2..090a2d9cb6e58c487e76c4ea81f5670a1c2e5ecc 100644 (file)
@@ -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) {
index 1b86770d9399f410ebfe5fde40740d0b9f614413..ad4de0e0e6ffff7b2ff26cee25627ea6878da747 100644 (file)
@@ -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