From a8218a39511e55b8d2c869b5daf3f26519f73cec Mon Sep 17 00:00:00 2001 From: Hannes Roth Date: Tue, 19 Aug 2014 15:26:47 -0700 Subject: [PATCH] (Wangle) Optimize empty continuation 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/folly/wangle/detail/State.h b/folly/wangle/detail/State.h index 1e98e4e3..b93e9ea6 100644 --- a/folly/wangle/detail/State.h +++ b/folly/wangle/detail/State.h @@ -29,6 +29,11 @@ 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 +void empty_callback(Try&&) { } + /** The shared state object for Future and Promise. */ template class State { @@ -107,7 +112,7 @@ class State { // Called by a destructing Future void detachFuture() { if (!callback_) { - setCallback([](Try&&) {}); + setCallback(empty_callback); } activate(); detachOne(); -- 2.34.1