Przeglądaj źródła

storage: small improvement for shrink_to_size

skypjack 3 tygodni temu
rodzic
commit
b1758e221b
2 zmienionych plików z 8 dodań i 6 usunięć
  1. 1 1
      TODO
  2. 7 5
      src/entt/entity/storage.hpp

+ 1 - 1
TODO

@@ -34,9 +34,9 @@ TODO:
 * organizer: view/storage only based model, no registry
 * introduce a way to inject stl from outside too
 * redesign snapshot as a whole
-* storage: trivial destructor on exit (ie shrink_to_size) and clear/pop_all
 * 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

+ 7 - 5
src/entt/entity/storage.hpp

@@ -261,13 +261,15 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
         const auto from = (sz + traits_type::page_size - 1u) / traits_type::page_size;
         allocator_type allocator{get_allocator()};
 
-        for(auto pos = sz, length = base_type::size(); pos < length; ++pos) {
-            if constexpr(traits_type::in_place_delete) {
-                if(base_type::data()[pos] != tombstone) {
+        if constexpr(!std::is_trivially_destructible_v<element_type>) {
+            for(auto pos = sz, length = base_type::size(); pos < length; ++pos) {
+                if constexpr(traits_type::in_place_delete) {
+                    if(base_type::data()[pos] != tombstone) {
+                        alloc_traits::destroy(allocator, std::addressof(element_at(pos)));
+                    }
+                } else {
                     alloc_traits::destroy(allocator, std::addressof(element_at(pos)));
                 }
-            } else {
-                alloc_traits::destroy(allocator, std::addressof(element_at(pos)));
             }
         }