Inline the lower_bound and upper_bound callbacks in sorted_vector_map
authorYedidya Feldblum <yfeldblum@fb.com>
Tue, 12 Jul 2016 01:27:49 +0000 (18:27 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Tue, 12 Jul 2016 01:38:54 +0000 (18:38 -0700)
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

index e9f77d3a5eb13a2a5f592ff1097686687973a507..aa2f0420b360283cdb397b49e16d6473842f3aa7 100644 (file)
@@ -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<iterator,iterator> 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);
   }