[Lldb-commits] [PATCH] D150219: [lldb][NFCI] Remove n^2 loops and simplify iterator usage
Felipe de Azevedo Piovezan via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Tue May 9 12:56:04 PDT 2023
fdeazeve added inline comments.
================
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())
----------------
jingham wrote:
> 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.
Yup, this was just a mistake on my part. Will address in the next version
================
Comment at: lldb/source/Utility/Broadcaster.cpp:392
}
- m_event_map.erase(iter);
+ iter = m_event_map.erase(iter);
}
----------------
bulbazord wrote:
> I don't think you need to actually capture the iterator here? std::map::erase doesn't invalidate existing iterators* (so `begin` and `end` are fine) and we redefine `iter` at the beginning of this loop.
>
> *:https://en.cppreference.com/w/cpp/container/map/erase
Argh, the variable `begin` shouldn't exist, it should all be `iter`, otherwise we're not addressing the quadratic behaviour.
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