Commit 0ad80e7c authored by Yuri Putivsky's avatar Yuri Putivsky Committed by afrind

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
parent cecc9aaa
...@@ -174,12 +174,24 @@ class ThreadPoolExecutor : public virtual Executor { ...@@ -174,12 +174,24 @@ class ThreadPoolExecutor : public virtual Executor {
class ThreadList { class ThreadList {
public: public:
void add(const ThreadPtr& state) { 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); vec_.insert(it, state);
} }
void remove(const ThreadPtr& 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(itPair.first != vec_.end());
CHECK(std::next(itPair.first) == itPair.second); CHECK(std::next(itPair.first) == itPair.second);
vec_.erase(itPair.first); vec_.erase(itPair.first);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment