|
|
@@ -234,26 +234,26 @@ protected:
|
|
|
|
|
|
/**
|
|
|
* @brief Erases an entity from a sparse set.
|
|
|
- * @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.
|
|
|
+ * @param it Iterator to the first element to erase.
|
|
|
+ * @param count Number of elements to erase.
|
|
|
*/
|
|
|
- virtual void try_erase(const basic_iterator first, const basic_iterator last) {
|
|
|
- for(auto it = first; it != last; ++it) {
|
|
|
- const auto pos = static_cast<size_type>(it.index());
|
|
|
- auto &ref = sparse_ref(*it);
|
|
|
-
|
|
|
- if(mode == deletion_policy::in_place) {
|
|
|
- packed[pos] = std::exchange(free_list, entity_traits::combine(static_cast<typename entity_traits::entity_type>(pos), entity_traits::reserved));
|
|
|
- } else {
|
|
|
- packed[pos] = packed.back();
|
|
|
- sparse_ref(packed.back()) = entity_traits::combine(static_cast<typename entity_traits::entity_type>(pos), entity_traits::to_integral(packed.back()));
|
|
|
+ virtual void try_erase(basic_iterator it, const std::size_t count) {
|
|
|
+ if(mode == deletion_policy::in_place) {
|
|
|
+ for(const auto last = it + count; it != last; ++it) {
|
|
|
+ packed[it.index()] = std::exchange(free_list, entity_traits::combine(static_cast<typename entity_traits::entity_type>(it.index()), entity_traits::reserved));
|
|
|
+ sparse_ref(*it) = null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for(const auto last = it + count; it != last; ++it) {
|
|
|
+ auto &ref = sparse_ref(*it);
|
|
|
+ packed[it.index()] = packed.back();
|
|
|
+ sparse_ref(packed.back()) = entity_traits::combine(static_cast<typename entity_traits::entity_type>(it.index()), entity_traits::to_integral(packed.back()));
|
|
|
// unnecessary but it helps to detect nasty bugs
|
|
|
ENTT_ASSERT((packed.back() = tombstone, true), "");
|
|
|
packed.pop_back();
|
|
|
+ // lazy self-assignment guard
|
|
|
+ ref = null;
|
|
|
}
|
|
|
-
|
|
|
- // lazy self-assignment guard
|
|
|
- ref = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -696,8 +696,7 @@ public:
|
|
|
* @param entt A valid identifier.
|
|
|
*/
|
|
|
void erase(const entity_type entt) {
|
|
|
- const auto it = --(end() - index(entt));
|
|
|
- try_erase(it, it + 1u);
|
|
|
+ try_erase(--(end() - index(entt)), 1u);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -712,7 +711,7 @@ public:
|
|
|
template<typename It>
|
|
|
void erase(It first, It last) {
|
|
|
if constexpr(std::is_same_v<It, basic_iterator>) {
|
|
|
- try_erase(first, last);
|
|
|
+ try_erase(first, static_cast<size_type>(std::distance(first, last)));
|
|
|
} else {
|
|
|
for(; first != last; ++first) {
|
|
|
erase(*first);
|
|
|
@@ -909,7 +908,7 @@ public:
|
|
|
remove(entity);
|
|
|
}
|
|
|
} else {
|
|
|
- try_erase(begin(), end());
|
|
|
+ try_erase(begin(), size());
|
|
|
}
|
|
|
}
|
|
|
|