From: Hannes Roth Date: Tue, 19 Aug 2014 22:26:47 +0000 (-0700) Subject: (Wangle) Optimize empty continuation X-Git-Tag: v0.22.0~393 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a8218a39511e55b8d2c869b5daf3f26519f73cec;p=folly.git (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 --- 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();