(Wangle) Optimize empty continuation
authorHannes Roth <hannesr@fb.com>
Tue, 19 Aug 2014 22:26:47 +0000 (15:26 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Sep 2014 21:22:22 +0000 (14:22 -0700)
Summary: It should remove one malloc as per the task.

Test Plan: `fbconfig folly/wangle && fbmake runtests` Also, `--clang`.

Reviewed By: davejwatson@fb.com

Subscribers: fugalh

FB internal diff: D1498331

Tasks: 4913277

folly/wangle/detail/State.h

index 1e98e4e3bd003abfc32f7ac7af67aacb3c9b988b..b93e9ea6a324413b98649bede5586f40276640fa 100644 (file)
 
 namespace folly { namespace wangle { namespace detail {
 
+// As of GCC 4.8.1, the std::function in libstdc++ optimizes only for pointers
+// to functions, using a helper avoids a call to malloc.
+template<typename T>
+void empty_callback(Try<T>&&) { }
+
 /** The shared state object for Future and Promise. */
 template<typename T>
 class State {
@@ -107,7 +112,7 @@ class State {
   // Called by a destructing Future
   void detachFuture() {
     if (!callback_) {
-      setCallback([](Try<T>&&) {});
+      setCallback(empty_callback<T>);
     }
     activate();
     detachOne();