[all-commits] [llvm/llvm-project] 25495c: [lldb][NFCI] Remove n^2 loops and simplify iterato...

Felipe de Azevedo Piovezan via All-commits all-commits at lists.llvm.org
Wed May 10 03:19:45 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 25495c9b4c05cb52bacdbc91ba7ee7da7b9a857c
      https://github.com/llvm/llvm-project/commit/25495c9b4c05cb52bacdbc91ba7ee7da7b9a857c
  Author: Felipe de Azevedo Piovezan <fpiovezan at apple.com>
  Date:   2023-05-10 (Wed, 10 May 2023)

  Changed paths:
    M lldb/source/Utility/Broadcaster.cpp

  Log Message:
  -----------
  [lldb][NFCI] Remove n^2 loops and simplify iterator usage

The code inside Broadcaster makes usage of iterators using olden C++ coding
style. Hidden in this old style is a couple of N^2 loops: we iterate over a map
(sequentially), removing the first element that matches some predicate. The
search is _always_ done from the start of the map, which implies that, if the
map has N elements and if all matches happen on the second half of the map, then
we visit the first N/2 elements exactly N/2 * N/2 times.

Ideally some of the code here would benefit from `std::map`s own "erase_if", but
this is only available with C++20:
https://en.cppreference.com/w/cpp/container/map/erase_if

We spent quite some time trying to make these loops more elegant, but it is
surprisingly tricky to do so.

Differential Revision: https://reviews.llvm.org/D150219




More information about the All-commits mailing list