[Lldb-commits] [PATCH] D67123: [lldb] Use binary search in RangeDataVector:FindEntryIndexesThatContain

Adrian McCarthy via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 3 13:02:58 PDT 2019


amccarth added a comment.

This feels very familiar.  I think I've reviewed a similar change back when we first implemented minidumps.



================
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) {
----------------
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()));
```



Repository:
  rLLDB LLDB

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

https://reviews.llvm.org/D67123





More information about the lldb-commits mailing list