std::vector<bool> code cleanup fixes optimizations

François Dumont frs.dumont@gmail.com
Mon Jun 24 19:31:00 GMT 2019


Hi

     Any feedback regarding this patch ?

Thanks

On 5/14/19 7:46 AM, François Dumont wrote:
> Hi
>
>     This is the patch on vector<bool> to:
>
> - Optimize sizeof in Versioned namespace mode. We could go one step 
> further by removing _M_p from _M_finish and just transform it into an 
> offset but it is a little bit more impacting for the code.
>
> - Implement the swap optimization already done on main std::vector 
> template class.
>
> - Fix move constructor so that it is noexcept no matter allocator move 
> constructor noexcept qualification
>
> - Optimize move constructor with allocator when allocator type is 
> always equal.
>
> - Use shortcuts in C++11 by skipping the _M_XXX_dispatch methods. 
> Those are now defined only in pre-C++11 mode, I can't see any abi 
> issue in doing so.
>
>     * include/bits/stl_bvector.h
>     [_GLIBCXX_INLINE_VERSION](_Bvector_impl_data::_M_start): Define as
>     _Bit_type*.
>     (_Bvector_impl_data(const _Bvector_impl_data&)): Default.
>     (_Bvector_impl_data(_Bvector_impl_data&&)): Delegate to latter.
>     (_Bvector_impl_data::operator=(const _Bvector_impl_data&)): Default.
> (_Bvector_impl_data::_M_move_data(_Bvector_impl_data&&)): Use latter.
>     (_Bvector_impl_data::_M_reset()): Likewise.
>     (_Bvector_impl_data::_M_swap_data): New.
>     (_Bvector_impl::_Bvector_impl(_Bvector_impl&&)): Implement 
> explicitely.
>     (_Bvector_impl::_Bvector_impl(_Bit_alloc_type&&, 
> _Bvector_impl&&)): New.
>     (_Bvector_base::_Bvector_base(_Bvector_base&&, const 
> allocator_type&)):
>     New, use latter.
>     (vector::vector(vector&&, const allocator_type&, true_type)): New, 
> use
>     latter.
>     (vector::vector(vector&&, const allocator_type&, false_type)): New.
>     (vector::vector(vector&&, const allocator_type&)): Use latters.
>     (vector::vector(const vector&, const allocator_type&)): Adapt.
>     [__cplusplus >= 201103](vector::vector(_InputIt, _InputIt,
>     const allocator_type&)): Use _M_initialize_range.
>     (vector::operator[](size_type)): Use iterator operator[].
>     (vector::operator[](size_type) const): Use const_iterator operator[].
>     (vector::swap(vector&)): Adapt.
>     (vector::_M_initialize(size_type)): Add assertions on allocators.
>     Use _M_swap_data.
>     [__cplusplus >= 201103](vector::insert(const_iterator, _InputIt,
>     _InputIt)): Use _M_insert_range.
>     [__cplusplus >= 201103](vector::_M_initialize_dispatch): Remove.
>     [__cplusplus >= 201103](vector::_M_insert_dispatch): Remove.
>     * testsuite/23_containers/vector/bool/allocator/swap.cc: Adapt.
>     * 
> testsuite/23_containers/vector/bool/cons/noexcept_move_construct.cc:
>     Add check.
>
> Tested under Linux x86_64, normal and debug modes.
>
> Ok to commit ?
>
> François
>



More information about the Gcc-patches mailing list