From: Yuri Putivsky Date: Thu, 26 Mar 2015 19:04:03 +0000 (-0700) Subject: Fixing predicate inlining X-Git-Tag: v0.33.0~17 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0ad80e7c9972eeebf4f5e32b98ed627e00fd978b;p=folly.git Fixing predicate inlining Summary: as title. Test Plan: run unit tests Reviewed By: yfeldblum@fb.com Subscribers: ming, fugalh, folly-diffs@, jsedgwick, yfeldblum, ridge@ FB internal diff: D1946589 --- diff --git a/folly/wangle/concurrent/ThreadPoolExecutor.h b/folly/wangle/concurrent/ThreadPoolExecutor.h index 32a0330d..c8ca7bb1 100644 --- a/folly/wangle/concurrent/ThreadPoolExecutor.h +++ b/folly/wangle/concurrent/ThreadPoolExecutor.h @@ -174,12 +174,24 @@ class ThreadPoolExecutor : public virtual Executor { class ThreadList { public: void add(const ThreadPtr& state) { - auto it = std::lower_bound(vec_.begin(), vec_.end(), state, compare); + auto it = std::lower_bound(vec_.begin(), vec_.end(), state, + // compare method is a static method of class + // and therefore cannot be inlined by compiler + // as a template predicate of the STL algorithm + // but wrapped up with the lambda function (lambda will be inlined) + // compiler can inline compare method as well + [&](const ThreadPtr& ts1, const ThreadPtr& ts2) -> bool { // inline + return compare(ts1, ts2); + }); vec_.insert(it, state); } void remove(const ThreadPtr& state) { - auto itPair = std::equal_range(vec_.begin(), vec_.end(), state, compare); + auto itPair = std::equal_range(vec_.begin(), vec_.end(), state, + // the same as above + [&](const ThreadPtr& ts1, const ThreadPtr& ts2) -> bool { // inline + return compare(ts1, ts2); + }); CHECK(itPair.first != vec_.end()); CHECK(std::next(itPair.first) == itPair.second); vec_.erase(itPair.first);