@@ -298,6 +298,18 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
298
298
payload.resize (from);
299
299
}
300
300
301
+ void swap_at (const std::size_t from, const std::size_t to) {
302
+ using std::swap;
303
+ swap (element_at (from), element_at (to));
304
+ }
305
+
306
+ void move_to (const std::size_t from, const std::size_t to) {
307
+ auto &elem = element_at (from);
308
+ allocator_type allocator{get_allocator ()};
309
+ entt::uninitialized_construct_using_allocator (to_address (assure_at_least (to)), allocator, std::move (elem));
310
+ alloc_traits::destroy (allocator, std::addressof (elem));
311
+ }
312
+
301
313
private:
302
314
[[nodiscard]] const void *get_at (const std::size_t pos) const final {
303
315
return std::addressof (element_at (pos));
@@ -309,20 +321,10 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
309
321
ENTT_ASSERT ((from + 1u ) && !is_pinned_type, " Pinned type" );
310
322
311
323
if constexpr (!is_pinned_type) {
312
- auto &elem = element_at (from);
313
-
314
324
if constexpr (traits_type::in_place_delete) {
315
- if (base_type::operator [](to) == tombstone) {
316
- allocator_type allocator{get_allocator ()};
317
- entt::uninitialized_construct_using_allocator (to_address (assure_at_least (to)), allocator, std::move (elem));
318
- alloc_traits::destroy (allocator, std::addressof (elem));
319
- } else {
320
- using std::swap;
321
- swap (elem, element_at (to));
322
- }
325
+ (base_type::operator [](to) == tombstone) ? move_to (from, to) : swap_with (from, to);
323
326
} else {
324
- using std::swap;
325
- swap (elem, element_at (to));
327
+ swap_with (from, to);
326
328
}
327
329
}
328
330
}
0 commit comments