storage: make shrink_to_size check for tombstones only when needed

This commit is contained in:
Michele Caini
2022-01-03 21:29:22 +01:00
parent 87ef713a17
commit dedbe3d431

View File

@@ -270,13 +270,15 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
}
void shrink_to_size(const std::size_t sz) {
for(auto pos = sz, last = base_type::size(); pos < last; ++pos) {
if constexpr(comp_traits::in_place_delete) {
if(base_type::slot() == base_type::size()) {
for(auto pos = sz, last = base_type::size(); pos < last; ++pos) {
std::destroy_at(std::addressof(element_at(pos)));
}
} else {
for(auto pos = sz, last = base_type::size(); pos < last; ++pos) {
if(base_type::at(pos) != tombstone) {
std::destroy_at(std::addressof(element_at(pos)));
}
} else {
std::destroy_at(std::addressof(element_at(pos)));
}
}