libstdc++: Simplify emplace member functions in _Rb_tree
authorJonathan Wakely <jwakely@redhat.com>
Fri, 3 Dec 2021 11:16:30 +0000 (11:16 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 3 Dec 2021 22:52:27 +0000 (22:52 +0000)
commitbf548ce3e67276aa429b462cf41e68891fdf40c2
tree313a70b2cb1aaf41a37fbeedfc9f7d01c1815208
parentf78eaffd1538efb46953a8bf90e9b95661fcfb33
libstdc++: Simplify emplace member functions in _Rb_tree

This introduces a new RAII type to simplify the emplace members which
currently use try-catch blocks to deallocate a node if an exception is
thrown by the comparisons done during insertion. The new type is created
on the stack and manages the allocation of a new node and deallocates it
in the destructor if it wasn't inserted into the tree. It also provides
helper functions for doing the insertion, releasing ownership of the
node to the tree.

Also, we don't need to use long qualified names if we put the return
type after the nested-name-specifier.

libstdc++-v3/ChangeLog:

* include/bits/stl_tree.h (_Rb_tree::_Auto_node): Define new
RAII helper for creating and inserting new nodes.
(_Rb_tree::_M_insert_node): Use trailing-return-type to simplify
out-of-line definition.
(_Rb_tree::_M_insert_lower_node): Likewise.
(_Rb_tree::_M_insert_equal_lower_node): Likewise.
(_Rb_tree::_M_emplace_unique): Likewise. Use _Auto_node.
(_Rb_tree::_M_emplace_equal): Likewise.
(_Rb_tree::_M_emplace_hint_unique): Likewise.
(_Rb_tree::_M_emplace_hint_equal): Likewise.
libstdc++-v3/include/bits/stl_tree.h