https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112934
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jonathan Wakely <r...@gcc.gnu.org>: https://gcc.gnu.org/g:7c2e60f67a02d17d8c2f67ba438fdb50d51bc9f4 commit r16-284-g7c2e60f67a02d17d8c2f67ba438fdb50d51bc9f4 Author: Barnabás PÅcze <po...@protonmail.com> Date: Mon Mar 11 23:35:50 2024 +0000 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.