Revert "Using emplace_back to avoid temporary"
authorSara Golemon <sgolemon@fb.com>
Sat, 13 Jun 2015 02:11:17 +0000 (19:11 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 15 Jun 2015 20:34:36 +0000 (13:34 -0700)
Summary: This reverts commit 0968dcc2f0e02998fa53007853e0c0aad0a423b7.

Reverts D2151582

Reviewed By: @​iainb

Differential Revision: D2153840

folly/Padded.h
folly/io/async/test/AsyncSocketTest2.cpp
folly/io/async/test/EventBaseTest.cpp
folly/io/async/test/HHWheelTimerTest.cpp
folly/test/small_vector_test.cpp
folly/test/sorted_vector_test.cpp
folly/wangle/concurrent/PriorityLifoSemMPMCQueue.h

index e359ea117d3b8a1123ef42d5da778dd14f9ae25b..c5b53a7c94ad88c6aef460e29ffd6193dd18046d 100644 (file)
@@ -350,7 +350,7 @@ class Adaptor {
 
   Adaptor(const Adaptor&) = default;
   Adaptor& operator=(const Adaptor&) = default;
 
   Adaptor(const Adaptor&) = default;
   Adaptor& operator=(const Adaptor&) = default;
-  Adaptor(Adaptor&& other) /* may throw */
+  Adaptor(Adaptor&& other)
     : c_(std::move(other.c_)),
       lastCount_(other.lastCount_) {
     other.lastCount_ = Node::kElementCount;
     : c_(std::move(other.c_)),
       lastCount_(other.lastCount_) {
     other.lastCount_ = Node::kElementCount;
@@ -426,7 +426,7 @@ class Adaptor {
 
   void push_back(value_type x) {
     if (lastCount_ == Node::kElementCount) {
 
   void push_back(value_type x) {
     if (lastCount_ == Node::kElementCount) {
-      c_.emplace_back();
+      c_.push_back(Node());
       lastCount_ = 0;
     }
     c_.back().data()[lastCount_++] = std::move(x);
       lastCount_ = 0;
     }
     c_.back().data()[lastCount_++] = std::move(x);
index f44d4fd52779806a9f47de97541f32e066529f8a..2f31124b6e959f06ebfe057320868f81642231b3 100644 (file)
@@ -1443,28 +1443,28 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
 
   void connectionAccepted(int fd, const folly::SocketAddress& clientAddr)
       noexcept {
 
   void connectionAccepted(int fd, const folly::SocketAddress& clientAddr)
       noexcept {
-    events_.emplace_back(fd, clientAddr);
+    events_.push_back(EventInfo(fd, clientAddr));
 
     if (connectionAcceptedFn_) {
       connectionAcceptedFn_(fd, clientAddr);
     }
   }
   void acceptError(const std::exception& ex) noexcept {
 
     if (connectionAcceptedFn_) {
       connectionAcceptedFn_(fd, clientAddr);
     }
   }
   void acceptError(const std::exception& ex) noexcept {
-    events_.emplace_back(ex.what());
+    events_.push_back(EventInfo(ex.what()));
 
     if (acceptErrorFn_) {
       acceptErrorFn_(ex);
     }
   }
   void acceptStarted() noexcept {
 
     if (acceptErrorFn_) {
       acceptErrorFn_(ex);
     }
   }
   void acceptStarted() noexcept {
-    events_.emplace_back(TYPE_START);
+    events_.push_back(EventInfo(TYPE_START));
 
     if (acceptStartedFn_) {
       acceptStartedFn_();
     }
   }
   void acceptStopped() noexcept {
 
     if (acceptStartedFn_) {
       acceptStartedFn_();
     }
   }
   void acceptStopped() noexcept {
-    events_.emplace_back(TYPE_STOP);
+    events_.push_back(EventInfo(TYPE_STOP));
 
     if (acceptStoppedFn_) {
       acceptStoppedFn_();
 
     if (acceptStoppedFn_) {
       acceptStoppedFn_();
index 5e8520eca9165f1c35fe1c5d005e6f80cdde0707..c0abf9b0135e77db6370e234bc2bdd1ae909455a 100644 (file)
@@ -155,7 +155,7 @@ class TestHandler : public EventHandler {
       bytesWritten = writeUntilFull(fd_);
     }
 
       bytesWritten = writeUntilFull(fd_);
     }
 
-    log.emplace_back(events, bytesRead, bytesWritten);
+    log.push_back(EventRecord(events, bytesRead, bytesWritten));
   }
 
   struct EventRecord {
   }
 
   struct EventRecord {
@@ -648,7 +648,7 @@ class PartialReadHandler : public TestHandler {
   virtual void handlerReady(uint16_t events) noexcept {
     assert(events == EventHandler::READ);
     ssize_t bytesRead = readFromFD(fd_, readLength_);
   virtual void handlerReady(uint16_t events) noexcept {
     assert(events == EventHandler::READ);
     ssize_t bytesRead = readFromFD(fd_, readLength_);
-    log.emplace_back(events, bytesRead, 0);
+    log.push_back(EventRecord(events, bytesRead, 0));
   }
 
  private:
   }
 
  private:
@@ -713,7 +713,7 @@ class PartialWriteHandler : public TestHandler {
   virtual void handlerReady(uint16_t events) noexcept {
     assert(events == EventHandler::WRITE);
     ssize_t bytesWritten = writeToFD(fd_, writeLength_);
   virtual void handlerReady(uint16_t events) noexcept {
     assert(events == EventHandler::WRITE);
     ssize_t bytesWritten = writeToFD(fd_, writeLength_);
-    log.emplace_back(events, 0, bytesWritten);
+    log.push_back(EventRecord(events, 0, bytesWritten));
   }
 
  private:
   }
 
  private:
@@ -934,7 +934,7 @@ class ReschedulingTimeout : public AsyncTimeout {
   }
 
   virtual void timeoutExpired() noexcept {
   }
 
   virtual void timeoutExpired() noexcept {
-    timestamps.emplace_back();
+    timestamps.push_back(TimePoint());
     reschedule();
   }
 
     reschedule();
   }
 
index 6cabc028174dd9b2f81cce3b6796458e5b81c77a..e2b5c096291601200d97dbc962ec9627f66e98b5 100644 (file)
@@ -37,14 +37,14 @@ class TestTimeout : public HHWheelTimer::Callback {
   }
 
   void timeoutExpired() noexcept override {
   }
 
   void timeoutExpired() noexcept override {
-    timestamps.emplace_back();
+    timestamps.push_back(TimePoint());
     if (fn) {
       fn();
     }
   }
 
   void callbackCanceled() noexcept override {
     if (fn) {
       fn();
     }
   }
 
   void callbackCanceled() noexcept override {
-    canceledTimestamps.emplace_back();
+    canceledTimestamps.push_back(TimePoint());
     if (fn) {
       fn();
     }
     if (fn) {
       fn();
     }
index 860fddc6b49ef1f777198d4c7bdc3611396fde44..616dfd2bbf32d6ee67941ef2b9bf08430fc42767 100644 (file)
@@ -159,7 +159,7 @@ struct TestBasicGuarantee {
   {
     throwCounter = 1000;
     for (int i = 0; i < prepopulate; ++i) {
   {
     throwCounter = 1000;
     for (int i = 0; i < prepopulate; ++i) {
-      vec.emplace_back();
+      vec.push_back(Thrower());
     }
   }
 
     }
   }
 
@@ -203,7 +203,7 @@ TEST(small_vector, BasicGuarantee) {
     (TestBasicGuarantee(prepop))( // parens or a mildly vexing parse :(
       1,
       [&] (folly::small_vector<Thrower,3>& v) {
     (TestBasicGuarantee(prepop))( // parens or a mildly vexing parse :(
       1,
       [&] (folly::small_vector<Thrower,3>& v) {
-        v.emplace_back();
+        v.push_back(Thrower());
       }
     );
 
       }
     );
 
@@ -232,9 +232,9 @@ TEST(small_vector, BasicGuarantee) {
     3,
     [&] (folly::small_vector<Thrower,3>& v) {
       std::vector<Thrower> b;
     3,
     [&] (folly::small_vector<Thrower,3>& v) {
       std::vector<Thrower> b;
-      b.emplace_back();
-      b.emplace_back();
-      b.emplace_back();
+      b.push_back(Thrower());
+      b.push_back(Thrower());
+      b.push_back(Thrower());
 
       /*
        * Apparently if you do the following initializer_list instead
 
       /*
        * Apparently if you do the following initializer_list instead
@@ -251,7 +251,7 @@ TEST(small_vector, BasicGuarantee) {
     [&] (folly::small_vector<Thrower,3>& v) {
       std::vector<Thrower> b;
       for (int i = 0; i < 6; ++i) {
     [&] (folly::small_vector<Thrower,3>& v) {
       std::vector<Thrower> b;
       for (int i = 0; i < 6; ++i) {
-        b.emplace_back();
+        b.push_back(Thrower());
       }
 
       v.insert(v.begin() + 1, b.begin(), b.end());
       }
 
       v.insert(v.begin() + 1, b.begin(), b.end());
index e1366787ab00a4df74b5a71d17259f47c8b9a51e..939a085df2ac77e97c48c437d9525fd95b95fc95 100644 (file)
@@ -280,7 +280,7 @@ TEST(SortedVectorTypes, GrowthPolicy) {
 
   std::list<CountCopyCtor> v;
   for (int i = 0; i < 20; ++i) {
 
   std::list<CountCopyCtor> v;
   for (int i = 0; i < 20; ++i) {
-    v.emplace_back(20 + i);
+    v.push_back(CountCopyCtor(20 + i));
   }
   a.insert(v.begin(), v.end());
   check_invariant(a);
   }
   a.insert(v.begin(), v.end());
   check_invariant(a);
index 3a831fa33ceaf765aa0afab51f7ba23033553aa9..583a9a34b34001a9c9718e674e9d617c1caead55 100644 (file)
@@ -27,7 +27,7 @@ class PriorityLifoSemMPMCQueue : public BlockingQueue<T> {
   explicit PriorityLifoSemMPMCQueue(uint8_t numPriorities, size_t capacity) {
     queues_.reserve(numPriorities);
     for (int8_t i = 0; i < numPriorities; i++) {
   explicit PriorityLifoSemMPMCQueue(uint8_t numPriorities, size_t capacity) {
     queues_.reserve(numPriorities);
     for (int8_t i = 0; i < numPriorities; i++) {
-      queues_.emplace_back(capacity);
+      queues_.push_back(MPMCQueue<T>(capacity));
     }
   }
 
     }
   }