diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index a9f8daf23..5c17ff2f2 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -241,6 +241,25 @@ protected: head = static_cast(len); } + /** + * @brief Erases an entity from a sparse set. + * @param it An iterator to the element to pop. + */ + void swap_only(const basic_iterator it) { + ENTT_ASSERT(mode == deletion_policy::swap_only, "Deletion policy mismatched"); + + if(const auto pos = static_cast(index(*it)); pos < head) { + bump(traits_type::next(*it)); + + if(const auto slot = head - 1u; pos != slot) { + swap_elements(packed[pos], packed[slot]); + } + + // partition check support in derived classes + --head; + } + } + /** * @brief Erases an entity from a sparse set. * @param it An iterator to the element to pop. @@ -287,7 +306,9 @@ protected: } break; case deletion_policy::swap_only: - // no-op + for(; first != last; ++first) { + swap_only(first); + } break; } } diff --git a/src/entt/entity/storage.hpp b/src/entt/entity/storage.hpp index 87bd780d3..762214b19 100644 --- a/src/entt/entity/storage.hpp +++ b/src/entt/entity/storage.hpp @@ -971,25 +971,6 @@ private: } protected: - /** - * @brief Erases entities from a storage. - * @param first An iterator to the first element of the range of entities. - * @param last An iterator past the last element of the range of entities. - */ - void pop(underlying_iterator first, underlying_iterator last) override { - for(; first != last; ++first) { - if(const auto pos = base_type::index(*first); pos < base_type::free_list()) { - base_type::bump(local_traits_type::next(*first)); - - if(const size_type slot = base_type::free_list() - 1u; pos != slot) { - base_type::swap_elements(base_type::data()[pos], base_type::data()[slot]); - } - - base_type::swap_only_length_temporary_function(base_type::free_list() - 1u); - } - } - } - /** * @brief Assigns an entity to a storage. * @param hint A valid identifier. @@ -1147,7 +1128,7 @@ public: * @param first An iterator to the first element of the range to generate. * @param last An iterator past the last element of the range to generate. */ - template + template void insert(It first, It last) { for(const auto sz = base_type::size(); first != last && base_type::free_list() != sz; ++first, base_type::swap_only_length_temporary_function(base_type::free_list() + 1u)) { *first = base_type::operator[](base_type::free_list());