[all-commits] [llvm/llvm-project] f01958: [SmallPtrSet] Add remove_if() method (#96468)

Nikita Popov via All-commits all-commits at lists.llvm.org
Tue Jun 25 00:02:03 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f01958137f358f4fd3e71636b187db14a37a5853
      https://github.com/llvm/llvm-project/commit/f01958137f358f4fd3e71636b187db14a37a5853
  Author: Nikita Popov <npopov at redhat.com>
  Date:   2024-06-25 (Tue, 25 Jun 2024)

  Changed paths:
    M llvm/include/llvm/ADT/SmallPtrSet.h
    M llvm/unittests/ADT/SmallPtrSetTest.cpp

  Log Message:
  -----------
  [SmallPtrSet] Add remove_if() method (#96468)

Add remove_if() method, similar to the one already present on SetVector.
It is intended to replace the following pattern:

    for (Foo *Ptr : Set)
      if (Pred(Ptr))
        Set.erase(Ptr);

With:

    Set.remove_if(Pred);

This pattern is commonly used for set intersection, where `Pred` is
something like `!OtherSet.contains(Ptr)`.

The implementation provided here is a bit more efficient than the naive
loop, because it does not require looking up the bucket during the
erase() operation again.

However, my actual motivation for this is to have a way to perform this
operation without relying on the current `std::set`-style guarantee that
erase() does not invalidate iterators. I'd like to stop making use of
tombstones in the small regime, which will make insertion operations a
good bit more efficient. However, this will invalidate iterators during
erase().



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list