diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 46b21999e..abec552e0 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -336,17 +336,21 @@ protected: /*! @brief Erases all entities of a storage. */ void pop_all() override { - allocator_type allocator{get_allocator()}; + if constexpr(std::is_trivially_destructible_v) { + base_type::pop_all(); + } else { + allocator_type allocator{get_allocator()}; - for(auto first = base_type::begin(); !(first.index() < 0); ++first) { - if constexpr(traits_type::in_place_delete) { - if(*first != tombstone) { - base_type::in_place_pop(first); + for(auto first = base_type::begin(); !(first.index() < 0); ++first) { + if constexpr(traits_type::in_place_delete) { + if(*first != tombstone) { + base_type::in_place_pop(first); + alloc_traits::destroy(allocator, std::addressof(element_at(static_cast(first.index())))); + } + } else { + base_type::swap_and_pop(first); alloc_traits::destroy(allocator, std::addressof(element_at(static_cast(first.index())))); } - } else { - base_type::swap_and_pop(first); - alloc_traits::destroy(allocator, std::addressof(element_at(static_cast(first.index())))); } } }