We might avoid some temporaries
authorPraveen Kumar <cpp.fool@gmail.com>
Fri, 13 Mar 2015 04:55:34 +0000 (10:25 +0530)
committerAndre Azevedo <aap@fb.com>
Wed, 18 Mar 2015 03:18:46 +0000 (20:18 -0700)
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

index da84c68b5002c814d4e1720bf3b1296530e449f5..5e2c67725a4cef870efd7c712cc8e7e7f53f60fb 100644 (file)
@@ -264,8 +264,7 @@ void AsyncServerSocket::useExistingSockets(const std::vector<int>& 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.
   //