[Lldb-commits] [PATCH] D150219: [lldb][NFCI] Remove n^2 loops and simplify iterator usage
Jim Ingham via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue May 9 12:37:27 PDT 2023
jingham accepted this revision.
jingham added a comment.
You are inconsistent in a couple of places about whether you re-look up m_event_map.end or use the version you captured in a variable, which is a little confusing. Other than that this looks equivalent
================
Comment at: lldb/source/Utility/Broadcaster.cpp:381
+ for (auto begin = m_event_map.begin(), end = m_event_map.end();;) {
+ auto iter = find_if(begin, end, listener_matches_and_shared_bits);
+ if (iter == m_event_map.end())
----------------
Why do you re-look-up `m_event_map.end()` instead of using the `end` variable you defined in the `for` initializer?
std::map::erase says it only invalidates iterators to the erased element, so you should be fine to use `end` here (and since you do exactly that in the previous line) it should be good here too.
================
Comment at: lldb/source/Utility/Broadcaster.cpp:436
+ iter = find_if(iter, end, events_predicate);
+ if (iter == m_event_map.end())
break;
----------------
fdeazeve wrote:
> this should be `== end`
Again here, you don't trust the "end" variable, but then in the next function you do reuse end_iter.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150219/new/
https://reviews.llvm.org/D150219
More information about the lldb-commits
mailing list