libstdc++: Avoid debug checks in uniform container erasure functions
authorJonathan Wakely <jwakely@redhat.com>
Thu, 7 Oct 2021 13:40:26 +0000 (14:40 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 7 Oct 2021 16:52:04 +0000 (17:52 +0100)
commit561078480ffb5adb68577276c6b23e4ee7b39272
tree0b8d2e4bfc2da06b79c03be3e05a28e01dac546e
parent5c1838c01652a403498e27024cb0e5ea66376353
libstdc++: Avoid debug checks in uniform container erasure functions

In commit r12-4083 I tried to make the std::erase and std::erase_if
function avoid the unnecessary overhead of safe iterators. It didn't
work, for two reasons. Firstly, for the RB tree containers the
__niter_base function is a no-op (because the iterators aren't
random access) so the safe iterators were still used. Secondly, for the
cases where __niter_base did remove the safe iterator layer, there was
still unnecessary overhead to create a new safe iterator and link it to
the container.

This solves the problem by simply binding a reference to the non-debug
version of the conainer. For normal mode this is a no-op, and for debug
mode it binds a reference to the debug container's base class. That
means the rest of the function operates directly on the non-debug
container, and avoids all checking.

For std::basic_string there's no need to unwrap anything, because we use
std::basic_string directly in debug mode anyway.

libstdc++-v3/ChangeLog:

* include/bits/erase_if.h (__erase_nodes_if): Remove redundant
__niter_base calls.
* include/std/string (erase, erase_if): Likewise.
* include/std/deque (erase, erase_if): Access non-debug
container directly.
* include/std/map (erase, erase_if): Likewise.
* include/std/set (erase, erase_if): Likewise.
* include/std/unordered_map (erase, erase_if): Likewise.
* include/std/unordered_set (erase, erase_if): Likewise.
* include/std/vector (erase, erase_if): Likewise.
* include/experimental/deque (erase, erase_if): Likewise.
* include/experimental/map (erase, erase_if): Likewise.
* include/experimental/set (erase, erase_if): Likewise.
* include/experimental/unordered_map (erase, erase_if):
Likewise.
* include/experimental/unordered_set (erase, erase_if):
Likewise.
* include/experimental/vector (erase, erase_if): Likewise.
14 files changed:
libstdc++-v3/include/bits/erase_if.h
libstdc++-v3/include/experimental/deque
libstdc++-v3/include/experimental/map
libstdc++-v3/include/experimental/set
libstdc++-v3/include/experimental/unordered_map
libstdc++-v3/include/experimental/unordered_set
libstdc++-v3/include/experimental/vector
libstdc++-v3/include/std/deque
libstdc++-v3/include/std/map
libstdc++-v3/include/std/set
libstdc++-v3/include/std/string
libstdc++-v3/include/std/unordered_map
libstdc++-v3/include/std/unordered_set
libstdc++-v3/include/std/vector