Deque code cleanup and optimizations
François Dumont
frs.dumont@gmail.com
Fri May 10 04:58:00 GMT 2019
Hi
   This patch implements a number of simplifications and optimizations
already done to other containers like std::vector
- Default default and move constructors
- The std::swap optimization
- The construction always equal allocator optimization
- Shortcuts on method calls.
   I remove several _M_map != nullptr checks cause in current
implementation it can't be null. I have several patches following this
one to support it but in this case we will be using a different code path.
   Now that we take shortcuts in several methods in C++11 there are
some that are simply unused in C++11 mode. For the moment I kept them as
long as we are not in versioned namespace scope in order to maintain abi
compatibility, I wonder if I really need to consider abi
backward-compatibility here ?
   * include/bits/stl_deque.h (_Deque_base(_Deque_base&&, false_type)):
   Make private.
   (_Deque_base(_Deque_base&&, true_type)): Likewise. Remove _M_map check.
   (_Deque_base(_Deque_base&&, const allocator_type&)): New.
   (_Deque_base(_Deque_base&&, const allocator_type&, size_t)): Remove
   _M_map check.
   (_Deque_base::_Deque_impl_data): New.
   (_Deque_base::_Deque_impl): Inherit latter.
   (_Deque_base::_Deque_impl::_M_swap_data): Move...
   (_Deque_base::_Deque_impl_data::_M_swap_data): ... here.
   (_Deque_base::_Deque_impl()): Add noexcept qualification.
   (_Deque_base::_Deque_impl(_Deque_impl&&, _Tp_alloc_type&&)): New.
   (_Deque_base::_Deque_impl::_M_get_Tp_allocator()): Remove static_cast.
   (_Deque_base::_Deque_impl::_M_move_impl()): Remove _M_impl._M_map
check.
   (deque<>::deque()): Default.
   (deque<>::deque(deque&&)): Default.
   (deque<>::deque(deque&&, const allocator_type&, false_type)): New.
   (deque<>::deque(deque&&, const allocator_type&, true_type)): New.
   (deque<>::deque(deque&&, const allocator_type&)): Delegate to latters.
   (deque<>::deque<_It>(_It, _It, const allocator_type&)): Use
   _M_range_initialize.
   (deque<>::assign<_It>(_It, _It)): Use _M_assign_aux.
   (deque<>::resize(size_type, const value_type&)): Share a single
   implementation.
   (deque<>::insert<_It>(const_iterator, _It, _It)): Use
   _M_range_insert_aux.
   [__cplusplus >= 201103L &&
_GLIBCXX_INLINE_VERSION](_M_initialize_dispatch):
   Remove.
   [__cplusplus >= 201103L &&
_GLIBCXX_INLINE_VERSION](_M_assign_dispatch):
   Remove.
   [__cplusplus >= 201103L &&
_GLIBCXX_INLINE_VERSION](_M_insert_dispatch):
   Remove.
   * testsuite/23_containers/deque/allocator/default_init.cc: New.
Tested under Linux x86_64 normal and debug modes.
Ok to commit ?
François
-------------- next part --------------
A non-text attachment was scrubbed...
Name: deque.patch
Type: text/x-patch
Size: 15508 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20190510/a9e66893/attachment.bin>
More information about the Libstdc++
mailing list