Skip to content

Commit 7a05a16

Browse files
committed
registry: slightly better destroy (yet not quite there though)
1 parent d085464 commit 7a05a16

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/entt/entity/registry.hpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,31 @@ class basic_registry {
801801
*/
802802
template<typename It>
803803
void destroy(It first, It last) {
804-
for(; first != last; ++first) {
805-
destroy(*first);
804+
if constexpr(std::is_same_v<It, typename basic_common_type::iterator>) {
805+
basic_common_type *owner = nullptr;
806+
807+
for(size_type pos = pools.size(); pos; --pos) {
808+
if(pools.begin()[pos - 1u].second->data() == first.data()) {
809+
owner = pools.begin()[pos - 1u].second.get();
810+
} else {
811+
pools.begin()[pos - 1u].second->remove(first, last);
812+
}
813+
}
814+
815+
if(owner) {
816+
// waiting to further/completely optimize this with the entity storage
817+
for(; first != last; ++first) {
818+
const auto entt = *first;
819+
owner->remove(entt);
820+
release(entt);
821+
}
822+
} else {
823+
release(std::move(first), std::move(last));
824+
}
825+
} else {
826+
for(; first != last; ++first) {
827+
destroy(*first);
828+
}
806829
}
807830
}
808831

0 commit comments

Comments
 (0)