@@ -970,7 +970,7 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
970970 {
971971 return *this ;
972972 }
973- this ->destroy ( );
973+ destroy_deque_controller ( this ->controller );
974974 this ->controller = other.controller ;
975975 other.controller = {{}, {}, {}};
976976 return *this ;
@@ -979,18 +979,18 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
979979private:
980980 struct run_destroy
981981 {
982- deque *thisdeq {};
982+ controller_type *thiscontroller {};
983983 inline constexpr run_destroy () noexcept = default;
984- inline explicit constexpr run_destroy (deque *p) noexcept
985- : thisdeq (p)
984+ inline explicit constexpr run_destroy (controller_type *p) noexcept
985+ : thiscontroller (p)
986986 {}
987987 inline run_destroy (run_destroy const &) = delete;
988988 inline run_destroy &operator =(run_destroy const &) = delete ;
989989 inline constexpr ~run_destroy ()
990990 {
991- if (thisdeq )
991+ if (thiscontroller )
992992 {
993- thisdeq-> destroy ( );
993+ destroy_deque_controller (*thiscontroller );
994994 }
995995 }
996996 };
@@ -1009,10 +1009,62 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
10091009 }
10101010 return ;
10111011 }
1012+ else
1013+ {
1014+ if (fromcontroller.front_block .curr_ptr == fromcontroller.back_block .curr_ptr )
1015+ {
1016+ this ->controller = {{}, {}, {}};
1017+ return ;
1018+ }
1019+
1020+ auto front_controller_ptr{fromcontroller.front_block .controller_ptr };
1021+ auto back_controller_ptr{fromcontroller.back_block .controller_ptr };
1022+ ::std::size_t blocks_required{static_cast <::std::size_t >(back_controller_ptr -
1023+ front_controller_ptr + 1 )};
1024+ constexpr ::std::size_t block_bytes{block_size * sizeof (value_type)};
1025+ ::fast_io::containers::details::deque_allocate_init_blocks_dezeroing_impl<allocator>(controller, alignof (value_type), block_bytes, blocks_required, false );
1026+
1027+ run_destroy destroyer (__builtin_addressof (this ->controller ));
1028+ auto dq_back_backup{this ->controller .back_block };
1029+ this ->controller .back_block = this ->controller .front_block ;
1030+ pointer lastblockbegin;
1031+ if (front_controller_ptr == back_controller_ptr)
1032+ {
1033+ lastblockbegin = controller.front_block .curr_ptr ;
1034+ }
1035+ else
1036+ {
1037+ auto destit{controller.front_block .controller_ptr };
1038+ auto pos{fromcontroller.front_block .curr_ptr - fromcontroller.front_block .begin_ptr };
1039+ ::std::uninitialized_copy (
1040+ fromcontroller.front_block.curr_ptr,
1041+ fromcontroller.front_block.end_ptr,
1042+ (controller.front_block.curr_ptr =
1043+ pos + controller.front_block.begin_ptr));
1044+ this ->controller .back_block .curr_ptr = controller.front_block .end_ptr =
1045+ controller.front_block .begin_ptr + block_size;
1046+ ++destit;
1047+ for (pointer *it{front_controller_ptr + 1 }, *ed{back_controller_ptr}; it != ed; ++it)
1048+ {
1049+ pointer blockptr{*it};
1050+ ::std::uninitialized_copy_n (blockptr, block_size, *destit);
1051+ this ->controller .back_block = {destit, blockptr, blockptr, blockptr + block_size};
1052+ ++destit;
1053+ }
1054+ lastblockbegin = fromcontroller.back_block .begin_ptr ;
1055+ }
1056+
1057+ dq_back_backup.curr_ptr =
1058+ ::std::uninitialized_copy (lastblockbegin,
1059+ fromcontroller.back_block.curr_ptr, dq_back_backup.begin_ptr);
1060+
1061+ this ->controller .back_block = dq_back_backup;
1062+ destroyer.thiscontroller = nullptr ;
1063+ }
10121064 }
10131065 inline constexpr void default_construct_impl ()
10141066 {
1015- run_destroy des (this );
1067+ run_destroy des (__builtin_addressof ( this -> controller ) );
10161068
10171069 auto dq_back_backup{controller.back_block };
10181070 controller.back_block = controller.front_block ;
@@ -1092,7 +1144,7 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
10921144 controller = {{}, {}, {}};
10931145 return ;
10941146 }
1095- run_destroy des (this );
1147+ run_destroy des (__builtin_addressof ( this -> controller ) );
10961148 if constexpr (::std::sized_sentinel_for<Sentinel, Iter>)
10971149 {
10981150 auto const dist{::std::ranges::distance (first, last)};
@@ -1148,7 +1200,7 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
11481200 ::fast_io::containers::details::deque_init_space_common<allocator, alignof (value_type), sizeof (value_type), block_size, iszeroconstr>(*reinterpret_cast <::fast_io::containers::details::deque_controller_common *>(__builtin_addressof (controller)), n);
11491201 }
11501202 }
1151- inline constexpr void destroy_all_elements () noexcept
1203+ inline static constexpr void destroy_all_elements (controller_type &controller ) noexcept
11521204 {
11531205 auto front_controller_ptr{controller.front_block .controller_ptr };
11541206 auto back_controller_ptr{controller.back_block .controller_ptr };
@@ -1170,11 +1222,11 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
11701222 ::std::destroy (lastblockbegin, controller.back_block.curr_ptr);
11711223 }
11721224
1173- inline constexpr void destroy ( ) noexcept
1225+ inline static constexpr void destroy_deque_controller (controller_type &controller ) noexcept
11741226 {
11751227 if constexpr (!::std::is_trivially_destructible_v<value_type>)
11761228 {
1177- this -> destroy_all_elements ();
1229+ destroy_all_elements (controller );
11781230 }
11791231 ::fast_io::containers::details::deque_destroy_trivial_common<allocator, alignof (value_type), sizeof (value_type)>(controller.controller_block );
11801232 }
@@ -1229,7 +1281,7 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
12291281 {
12301282 if constexpr (!::std::is_trivially_destructible_v<value_type>)
12311283 {
1232- this ->destroy_all_elements ( );
1284+ destroy_all_elements ( this ->controller );
12331285 }
12341286 if (__builtin_is_constant_evaluated ())
12351287 {
@@ -1593,13 +1645,13 @@ class deque FAST_IO_TRIVIALLY_RELOCATABLE_IF_ELIGIBLE
15931645
15941646 inline constexpr void clear_destroy () noexcept
15951647 {
1596- this ->destroy ( );
1648+ destroy_deque_controller ( this ->controller );
15971649 this ->controller = {{}, {}, {}};
15981650 }
15991651
16001652 inline constexpr ~deque ()
16011653 {
1602- this ->destroy ( );
1654+ destroy_deque_controller ( this ->controller );
16031655 }
16041656};
16051657
0 commit comments