diff --git a/TODO b/TODO index c4773eb16..81e01e7b0 100644 --- a/TODO +++ b/TODO @@ -37,6 +37,5 @@ TODO: * use the value type mixin more in the test suite to reduce the number of utility types * explore "runtime" mode for hashed string where the source is copied internally * swap_only/swap_and_pop/in_place_pop can (should?) accept the entity -* we can likely improve storage::pop for trivially destructible non in_place_delete types * storage: shrink_to_fit does not work with reentrant destructor? * test trivially_destructible optimization diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 4b89a5967..fd1a7562d 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -326,6 +326,9 @@ protected: if constexpr(traits_type::in_place_delete) { base_type::in_place_pop(first); alloc_traits::destroy(allocator, std::addressof(elem)); + } else if constexpr(std::is_trivially_destructible_v) { + elem = std::move(element_at(base_type::size() - 1u)); + base_type::swap_and_pop(first); } else { auto &other = element_at(base_type::size() - 1u); // destroying on exit allows reentrant destructors diff --git a/test/common/throwing_type.hpp b/test/common/throwing_type.hpp index aff856e27..4101187eb 100644 --- a/test/common/throwing_type.hpp +++ b/test/common/throwing_type.hpp @@ -16,6 +16,8 @@ struct throwing_type { } } + ~throwing_type() { /* make it non trivially destructible */ } + throwing_type &operator=(const throwing_type &other) { trigger = other.trigger; return *this;