From 1a8a56d10a058dc5d1bc7627cfddf83e976c34bb Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 14 Mar 2016 15:13:19 -0700 Subject: [PATCH] Use binary search in IndexSet::find() --- src/index_set.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/index_set.cpp b/src/index_set.cpp index 3468f439..e79d7a14 100644 --- a/src/index_set.cpp +++ b/src/index_set.cpp @@ -54,11 +54,8 @@ IndexSet::iterator IndexSet::find(size_t index) IndexSet::iterator IndexSet::find(size_t index, iterator it) { - for (auto end = m_ranges.end(); it != end; ++it) { - if (it->second > index) - return it; - } - return m_ranges.end(); + return std::lower_bound(it, m_ranges.end(), std::make_pair(size_t(0), index + 1), + [&](auto const& a, auto const& b) { return a.second < b.second; }); } void IndexSet::add(size_t index)