From 594f18f7ba21543612b02b97c3abdff7dd40aa3a Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Mon, 11 Jul 2016 18:27:49 -0700 Subject: [PATCH] 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 --- folly/sorted_vector_types.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) 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); } -- 2.34.1