From: Yedidya Feldblum Date: Tue, 12 Jul 2016 01:27:49 +0000 (-0700) Subject: Inline the lower_bound and upper_bound callbacks in sorted_vector_map X-Git-Tag: 2016.07.26~63 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=594f18f7ba21543612b02b97c3abdff7dd40aa3a Inline the lower_bound and upper_bound callbacks in sorted_vector_map Summary: [Folly] Inline the `lower_bound` and `upper_bound` callbacks in `sorted_vector_map`. Avoids unnecessary use of legacy `boost::bind`, and allows the compiler to avoid the indirection it introduces. This way, we use templates instead of vtables. Reviewed By: Orvid Differential Revision: D3545939 fbshipit-source-id: 277e9e4862beb71e99b94a62308783771071d2bc --- diff --git a/folly/sorted_vector_types.h b/folly/sorted_vector_types.h index e9f77d3a..aa2f0420 100644 --- a/folly/sorted_vector_types.h +++ b/folly/sorted_vector_types.h @@ -572,23 +572,27 @@ public: } iterator lower_bound(const key_type& key) { - return std::lower_bound(begin(), end(), key, - boost::bind(key_comp(), boost::bind(&value_type::first, _1), _2)); + auto c = key_comp(); + auto f = [&](const auto& a, const auto& b) { return c(a.first, b); }; + return std::lower_bound(begin(), end(), key, f); } const_iterator lower_bound(const key_type& key) const { - return std::lower_bound(begin(), end(), key, - boost::bind(key_comp(), boost::bind(&value_type::first, _1), _2)); + auto c = key_comp(); + auto f = [&](const auto& a, const auto& b) { return c(a.first, b); }; + return std::lower_bound(begin(), end(), key, f); } iterator upper_bound(const key_type& key) { - return std::upper_bound(begin(), end(), key, - boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2))); + auto c = key_comp(); + auto f = [&](const auto& a, const auto& b) { return c(a, b.first); }; + return std::upper_bound(begin(), end(), key, f); } const_iterator upper_bound(const key_type& key) const { - return std::upper_bound(begin(), end(), key, - boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2))); + auto c = key_comp(); + auto f = [&](const auto& a, const auto& b) { return c(a, b.first); }; + return std::upper_bound(begin(), end(), key, f); } std::pair equal_range(const key_type& key) { @@ -596,8 +600,9 @@ public: // argument types different from the iterator value_type, so we // have to do this. iterator low = lower_bound(key); - iterator high = std::upper_bound(low, end(), key, - boost::bind(key_comp(), _1, boost::bind(&value_type::first, _2))); + auto c = key_comp(); + auto f = [&](const auto& a, const auto& b) { return c(a, b.first); }; + iterator high = std::upper_bound(low, end(), key, f); return std::make_pair(low, high); }