]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Optimize removal from unique assoc containers [PR112934]
authorBarnabás Pőcze <pobrn@protonmail.com>
Mon, 11 Mar 2024 23:35:50 +0000 (23:35 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 29 Apr 2025 14:08:53 +0000 (15:08 +0100)
commit7c2e60f67a02d17d8c2f67ba438fdb50d51bc9f4
tree44b4cbcdd09c3f2bb92feb64dfe2ccda082f66b6
parent102eccaf8e2f914d3afbf7acfcee19bc5b240eca
libstdc++: Optimize removal from unique assoc containers [PR112934]

Previously, calling erase(key) on both std::map and std::set
would execute that same code that std::multi{map,set} would.
However, doing that is unnecessary because std::{map,set}
guarantee that all elements are unique.

It is reasonable to expect that erase(key) is equivalent
or better than:

  auto it = m.find(key);
  if (it != m.end())
    m.erase(it);

However, this was not the case. Fix that by adding a new
function _Rb_tree<>::_M_erase_unique() that is essentially
equivalent to the above snippet, and use this from both
std::map and std::set.

libstdc++-v3/ChangeLog:

PR libstdc++/112934
* include/bits/stl_map.h (map::erase): Use _M_erase_unique.
* include/bits/stl_set.h (set::erase): Likewise.
* include/bits/stl_tree.h (_Rb_tree::_M_erase_unique): Add.
libstdc++-v3/include/bits/stl_map.h
libstdc++-v3/include/bits/stl_set.h
libstdc++-v3/include/bits/stl_tree.h