From 0ad80e7c9972eeebf4f5e32b98ed627e00fd978b Mon Sep 17 00:00:00 2001 From: Yuri Putivsky Date: Thu, 26 Mar 2015 12:04:03 -0700 Subject: [PATCH] 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 --- folly/wangle/concurrent/ThreadPoolExecutor.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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); -- 2.34.1