Improve relocation

Marc Glisse marc.glisse@inria.fr
Fri Oct 26 12:02:00 GMT 2018


Hello,

here are some tweaks so that I can usefully mark deque as trivially 
relocatable. It includes more noexcept(auto) madness. For __relocate_a_1, 
I should also test if copying, ++ and != are noexcept, but I wanted to ask 
first because there might be restrictions on what iterators are allowed to 
do, even if I didn't see them. Also, the current code already ignores 
those, so it may as well be fixed in another patch.

Allocators are complicated. I specialized only for the default allocator, 
because that's by far the one that is used the most, and I have much less 
risk of getting it wrong. Some allocator expert is welcome to make a 
better test. I do not know in details how deque is implemented. A quick 
look seemed to show that trivial relocation should be fine, but I would 
appreciate a confirmation.

The extra parameter for __is_trivially_relocatable is not used, but I 
expect it will be as soon as the specializations of 
__is_trivially_relocatable become more advanced.

If I use or specialize __is_trivially_relocatable in many places, this 
forces to #include bits/stl_uninitialized.h in many places. I wonder if I 
should move some of that stuff. Since I may use it in std::swap, 
bits/move.h looks like a sensible place for the core pieces 
(__is_trivially_relocatable, and __relocate_object if I ever create that). 
That or type_traits.

Regtested on gcc112. I manually checked that there was a speed-up for 
operations on vector<deque<int>>, although doing any kind of benchmarking 
on gcc112 is hard, I'll test locally next time.

2018-10-26  Marc Glisse  <marc.glisse@inria.fr>

 	PR libstdc++/87106
 	* include/bits/stl_algobase.h: Include <type_traits>.
 	(__niter_base): Add noexcept specification.
 	* include/bits/stl_deque.h: Include <bits/stl_uninitialized.h>.
 	(__is_trivially_relocatable): Specialize for deque.
 	* include/bits/stl_iterator.h: Include <type_traits>.
 	(__niter_base): Add noexcept specification.
 	* include/bits/stl_uninitialized.h (__is_trivially_relocatable):
 	Add parameter for meta-programming.
 	(__relocate_a_1, __relocate_a): Add noexcept specification.
 	* include/bits/stl_vector.h (__use_relocate): Test __relocate_a.

-- 
Marc Glisse
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reloc.patch
Type: text/x-diff
Size: 8842 bytes
Desc: 
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20181026/c9db7c08/attachment.bin>


More information about the Libstdc++ mailing list