[PATCH] D67123: [lldb] Early exit in RangeDataVector:FindEntryIndexesThatContain

Adrian McCarthy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 09:27:40 PDT 2019


amccarth added inline comments.


================
Comment at: lldb/include/lldb/Utility/RangeMap.h:739
+    auto end = std::lower_bound(m_entries.begin(), m_entries.end(),
+                                Entry(addr, 1), BaseLessEqual);
+    for (auto I = m_entries.begin(); I != end; ++I) {
----------------
teemperor wrote:
> labath wrote:
> > amccarth wrote:
> > > You're trying to find an upper bound, so `std::upper_bound` seems more natural than `std::lower_bound`.  Understanding how `std::lower_bound` works with a comparator that implements `<=` requires some mental gymnastics.  With `std::upper_bound`, you'd just need `<` that compares only the base addresses.
> > > 
> > > You could even avoid the custom comparison function by using the maximum value for the size:
> > > 
> > > ```
> > >     auto end = std::upper_bound(m_entries.begin(), m_entries.end(),
> > >                                 Entry(addr, std::numeric_limits<Entry::SizeType>::max()));
> > > ```
> > > 
> > Actually, If I understand this correctly, there is no need for either lower or upper bound here. Since you're going to be iterating through the list anyway. It should be sufficient to add a early exit from the loop once you encounter an element whose base address is >= the address you search for.
> Oh true, I got confused by all the other lower_bounding we do in the surrounding functions :)
I still don't see the early exit from the loop.  Have you uploaded the latest diff to Phabricator?

(Thanks Pavel for pointing out the obvious that teemperor and I both missed.)


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67123/new/

https://reviews.llvm.org/D67123





More information about the llvm-commits mailing list