From 4cc84128538768f9a1ee2d1dfb51400e9f94fd88 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Fri, 13 Mar 2015 10:25:34 +0530 Subject: [PATCH] We might avoid some temporaries Summary: It seems we might avoid temporaries. To do so we pass arguments directly to constructors with the help of emplace_back member. Test Plan: all folly/tests, make check for 37 tests, passed. Closes https://github.com/facebook/folly/pull/150 Reviewed By: ldbrandy@fb.com Subscribers: lins, anca, folly-diffs@, yfeldblum FB internal diff: D1912505 Signature: t1:1912505:1426268158:086882bb53f3d79c3f3b7b2c362318f09b5ee3be --- folly/io/async/AsyncServerSocket.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index da84c68b..5e2c6772 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -264,8 +264,7 @@ void AsyncServerSocket::useExistingSockets(const std::vector& fds) { address.setFromLocalAddress(fd); setupSocket(fd); - sockets_.push_back( - ServerEventHandler(eventBase_, fd, this, address.getFamily())); + sockets_.emplace_back(eventBase_, fd, this, address.getFamily()); sockets_.back().changeHandlerFD(fd); } } @@ -292,8 +291,7 @@ void AsyncServerSocket::bindSocket( // If we just created this socket, update the EventHandler and set socket_ if (!isExistingSocket) { - sockets_.push_back( - ServerEventHandler(eventBase_, fd, this, address.getFamily())); + sockets_.emplace_back(eventBase_, fd, this, address.getFamily()); } } @@ -387,8 +385,7 @@ void AsyncServerSocket::bind(uint16_t port) { SocketAddress address; address.setFromLocalAddress(s); - sockets_.push_back( - ServerEventHandler(eventBase_, s, this, address.getFamily())); + sockets_.emplace_back(eventBase_, s, this, address.getFamily()); // Bind to the socket if (::bind(s, res->ai_addr, res->ai_addrlen) != 0) { @@ -506,7 +503,7 @@ void AsyncServerSocket::addAcceptCallback(AcceptCallback *callback, eventBase = eventBase_; // Run in AsyncServerSocket's eventbase } - callbacks_.push_back(CallbackInfo(callback, eventBase)); + callbacks_.emplace_back(callback, eventBase); // Start the remote acceptor. // -- 2.34.1