I was looking at the code in BreakpointList.cpp and found it deserved a quick cleanup.
- Extract duplicate code
- Use range-based for loop
- Use early return in loops
Paths
| Differential D56425
[BreakpointList] Simplify/modernize BreakpointList (NFC) ClosedPublic Authored by JDevlieghere on Jan 7 2019, 6:39 PM.
Details Summary I was looking at the code in BreakpointList.cpp and found it deserved a quick cleanup.
Diff Detail Event TimelineComment Actions I wonder if we should use a vector instead of a list here too. For small data sets a std::vector usually outperforms a std::list. I *think* the data-locality would outweigh the cost of copying the shared pointers. Comment Actions Looks like a nice/reasonable cleanup, thanks! Based on the coverage report (https://teemperor.de/lldb-coverage/coverage/Users/vsk/src/llvm.org-lldbsan/llvm/tools/lldb/source/Breakpoint/BreakpointList.cpp.html#L217) and benchmarks (https://teemperor.de/lldb-bench/static.html) GetBreakpointAtIndex doesn't looks that hot, so I'm not sure it's worth changing / accidentally regressing.
Comment Actions Second vote from me to switch to a std::vector since we have a function get breakpoint at index. Other than that, looks good.
Comment Actions
JDevlieghere added inline comments.
aprantl added inline comments. This revision is now accepted and ready to land.Jan 8 2019, 1:54 PM Comment Actions If we keep the list sorted we might be able to improve finding breakpoints by ID, but that can be done if we need to. BreakpointList::Add would need to insert it sorted, then we can get better than O(n) performance on FindBreakpointByID and Remove (anything that was using find_if when it is searching for a breakpoint by ID). Comment Actions
I'll do this as a follow-up. Closed by commit rLLDB350659: [BreakpointList] Simplify/modernize BreakpointList (NFC) (authored by JDevlieghere). · Explain WhyJan 8 2019, 2:11 PM This revision was automatically updated to reflect the committed changes. Comment Actions
On second thought, maybe it's not such a good idea after all. Internal breakpoints are negative so if we keep the vector sorted we'd always insert them at the front of the vector. We could change strategies based on whether the list is internal or not, but that seems overkill, especially given the code is not that hot as Vedant pointed out. Comment Actions
No worries. This is why I mentioned "if we need to". Fine to wait until we need to do this for some reason that proves to be an efficiency issue
Revision Contents
Diff 180728 include/lldb/Breakpoint/BreakpointList.h
source/Breakpoint/BreakpointList.cpp
|
perhaps: