Procházet zdrojové kódy

storage: refine from_placeholder function

Michele Caini před 1 rokem
rodič
revize
8b890993a2
2 změnil soubory, kde provedl 4 přidání a 3 odebrání
  1. 0 1
      TODO
  2. 4 2
      src/entt/entity/storage.hpp

+ 0 - 1
TODO

@@ -39,6 +39,5 @@ TODO:
 * return meta context from meta objects
 * allow passing arguments to meta setter/getter (we can fallback on meta invoke for everything probably)
 * delegate/sigh: forward connect/disconnect from & to *
-* update storage from_placeholder to avoid increasing placeholder if null
 * a few more tests on the improved shrink_to_fit for sparse arrays
 * meta_any::as_ref for void type invalidates the object (operator bool: true -> false)

+ 4 - 2
src/entt/entity/storage.hpp

@@ -989,8 +989,10 @@ class basic_storage<Entity, Entity, Allocator>
     using traits_type = entt_traits<Entity>;
 
     auto from_placeholder() noexcept {
-        ENTT_ASSERT(placeholder < traits_type::to_entity(null), "No more entities available");
-        return traits_type::combine(static_cast<typename traits_type::entity_type>(placeholder++), {});
+        const auto entt = traits_type::combine(static_cast<typename traits_type::entity_type>(placeholder), {});
+        ENTT_ASSERT(entt != null, "No more entities available");
+        placeholder += static_cast<size_type>(entt != null);
+        return entt;
     }
 
     auto next() noexcept {