Commit 8ce13dcc authored by Sara Golemon's avatar Sara Golemon

Revert "Using emplace_back to avoid temporary"

Summary: This reverts commit 0968dcc2f0e02998fa53007853e0c0aad0a423b7.

Reverts D2151582

Reviewed By: @​iainb

Differential Revision: D2153840
parent cbed8954
...@@ -350,7 +350,7 @@ class Adaptor { ...@@ -350,7 +350,7 @@ class Adaptor {
Adaptor(const Adaptor&) = default; Adaptor(const Adaptor&) = default;
Adaptor& operator=(const Adaptor&) = default; Adaptor& operator=(const Adaptor&) = default;
Adaptor(Adaptor&& other) /* may throw */ Adaptor(Adaptor&& other)
: c_(std::move(other.c_)), : c_(std::move(other.c_)),
lastCount_(other.lastCount_) { lastCount_(other.lastCount_) {
other.lastCount_ = Node::kElementCount; other.lastCount_ = Node::kElementCount;
...@@ -426,7 +426,7 @@ class Adaptor { ...@@ -426,7 +426,7 @@ class Adaptor {
void push_back(value_type x) { void push_back(value_type x) {
if (lastCount_ == Node::kElementCount) { if (lastCount_ == Node::kElementCount) {
c_.emplace_back(); c_.push_back(Node());
lastCount_ = 0; lastCount_ = 0;
} }
c_.back().data()[lastCount_++] = std::move(x); c_.back().data()[lastCount_++] = std::move(x);
......
...@@ -1443,28 +1443,28 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback { ...@@ -1443,28 +1443,28 @@ class TestAcceptCallback : public AsyncServerSocket::AcceptCallback {
void connectionAccepted(int fd, const folly::SocketAddress& clientAddr) void connectionAccepted(int fd, const folly::SocketAddress& clientAddr)
noexcept { noexcept {
events_.emplace_back(fd, clientAddr); events_.push_back(EventInfo(fd, clientAddr));
if (connectionAcceptedFn_) { if (connectionAcceptedFn_) {
connectionAcceptedFn_(fd, clientAddr); connectionAcceptedFn_(fd, clientAddr);
} }
} }
void acceptError(const std::exception& ex) noexcept { void acceptError(const std::exception& ex) noexcept {
events_.emplace_back(ex.what()); events_.push_back(EventInfo(ex.what()));
if (acceptErrorFn_) { if (acceptErrorFn_) {
acceptErrorFn_(ex); acceptErrorFn_(ex);
} }
} }
void acceptStarted() noexcept { void acceptStarted() noexcept {
events_.emplace_back(TYPE_START); events_.push_back(EventInfo(TYPE_START));
if (acceptStartedFn_) { if (acceptStartedFn_) {
acceptStartedFn_(); acceptStartedFn_();
} }
} }
void acceptStopped() noexcept { void acceptStopped() noexcept {
events_.emplace_back(TYPE_STOP); events_.push_back(EventInfo(TYPE_STOP));
if (acceptStoppedFn_) { if (acceptStoppedFn_) {
acceptStoppedFn_(); acceptStoppedFn_();
......
...@@ -155,7 +155,7 @@ class TestHandler : public EventHandler { ...@@ -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 { ...@@ -648,7 +648,7 @@ class PartialReadHandler : public TestHandler {
virtual void handlerReady(uint16_t events) noexcept { virtual void handlerReady(uint16_t events) noexcept {
assert(events == EventHandler::READ); assert(events == EventHandler::READ);
ssize_t bytesRead = readFromFD(fd_, readLength_); 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 { ...@@ -713,7 +713,7 @@ class PartialWriteHandler : public TestHandler {
virtual void handlerReady(uint16_t events) noexcept { virtual void handlerReady(uint16_t events) noexcept {
assert(events == EventHandler::WRITE); assert(events == EventHandler::WRITE);
ssize_t bytesWritten = writeToFD(fd_, writeLength_); 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 { ...@@ -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();
} }
......
...@@ -37,14 +37,14 @@ class TestTimeout : public HHWheelTimer::Callback { ...@@ -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) { if (fn) {
fn(); fn();
} }
} }
void callbackCanceled() noexcept override { void callbackCanceled() noexcept override {
canceledTimestamps.emplace_back(); canceledTimestamps.push_back(TimePoint());
if (fn) { if (fn) {
fn(); fn();
} }
......
...@@ -159,7 +159,7 @@ struct TestBasicGuarantee { ...@@ -159,7 +159,7 @@ struct TestBasicGuarantee {
{ {
throwCounter = 1000; throwCounter = 1000;
for (int i = 0; i < prepopulate; ++i) { for (int i = 0; i < prepopulate; ++i) {
vec.emplace_back(); vec.push_back(Thrower());
} }
} }
...@@ -203,7 +203,7 @@ TEST(small_vector, BasicGuarantee) { ...@@ -203,7 +203,7 @@ TEST(small_vector, BasicGuarantee) {
(TestBasicGuarantee(prepop))( // parens or a mildly vexing parse :( (TestBasicGuarantee(prepop))( // parens or a mildly vexing parse :(
1, 1,
[&] (folly::small_vector<Thrower,3>& v) { [&] (folly::small_vector<Thrower,3>& v) {
v.emplace_back(); v.push_back(Thrower());
} }
); );
...@@ -232,9 +232,9 @@ TEST(small_vector, BasicGuarantee) { ...@@ -232,9 +232,9 @@ TEST(small_vector, BasicGuarantee) {
3, 3,
[&] (folly::small_vector<Thrower,3>& v) { [&] (folly::small_vector<Thrower,3>& v) {
std::vector<Thrower> b; std::vector<Thrower> b;
b.emplace_back(); b.push_back(Thrower());
b.emplace_back(); b.push_back(Thrower());
b.emplace_back(); 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) { ...@@ -251,7 +251,7 @@ TEST(small_vector, BasicGuarantee) {
[&] (folly::small_vector<Thrower,3>& v) { [&] (folly::small_vector<Thrower,3>& v) {
std::vector<Thrower> b; std::vector<Thrower> b;
for (int i = 0; i < 6; ++i) { 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());
......
...@@ -280,7 +280,7 @@ TEST(SortedVectorTypes, GrowthPolicy) { ...@@ -280,7 +280,7 @@ TEST(SortedVectorTypes, GrowthPolicy) {
std::list<CountCopyCtor> v; std::list<CountCopyCtor> v;
for (int i = 0; i < 20; ++i) { for (int i = 0; i < 20; ++i) {
v.emplace_back(20 + i); v.push_back(CountCopyCtor(20 + i));
} }
a.insert(v.begin(), v.end()); a.insert(v.begin(), v.end());
check_invariant(a); check_invariant(a);
......
...@@ -27,7 +27,7 @@ class PriorityLifoSemMPMCQueue : public BlockingQueue<T> { ...@@ -27,7 +27,7 @@ class PriorityLifoSemMPMCQueue : public BlockingQueue<T> {
explicit PriorityLifoSemMPMCQueue(uint8_t numPriorities, size_t capacity) { explicit PriorityLifoSemMPMCQueue(uint8_t numPriorities, size_t capacity) {
queues_.reserve(numPriorities); queues_.reserve(numPriorities);
for (int8_t i = 0; i < numPriorities; i++) { for (int8_t i = 0; i < numPriorities; i++) {
queues_.emplace_back(capacity); queues_.push_back(MPMCQueue<T>(capacity));
} }
} }
......
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