Browse Source

get rid of registry::skip_family_pools

Michele Caini 6 years ago
parent
commit
eac944dbea
2 changed files with 6 additions and 9 deletions
  1. 0 1
      TODO
  2. 6 8
      src/entt/entity/registry.hpp

+ 0 - 1
TODO

@@ -35,5 +35,4 @@
 * named types: almost-stable index optimization for direct access to pools, no more linear searches
   - can implicitly generate types for meta benefit from a similar approach?
 * multi component registry::remove and some others?
-* get rid of registry::skip_family_pools
 * registry::prepare is unsafe

+ 6 - 8
src/entt/entity/registry.hpp

@@ -237,18 +237,17 @@ class basic_registry {
         pool_data *pdata = nullptr;
 
         if constexpr(is_named_type_v<Component>) {
-            const auto it = std::find_if(pools.begin()+skip_family_pools, pools.end(), [ctype](const auto &candidate) {
+            const auto it = std::find_if(pools.begin(), pools.end(), [ctype](const auto &candidate) {
                 return candidate.runtime_type == ctype;
             });
 
             pdata = (it == pools.cend() ? &pools.emplace_back() : &(*it));
         } else {
-            if(!(ctype < skip_family_pools)) {
-                pools.reserve(pools.size()+ctype-skip_family_pools+1);
-
-                while(!(ctype < skip_family_pools)) {
-                    pools.emplace(pools.begin()+(skip_family_pools++), pool_data{});
-                }
+            if(!(ctype < pools.size())) {
+                pools.resize(ctype+1);
+            } else if(pools[ctype].pool && pools[ctype].runtime_type != ctype) {
+                pools.emplace_back();
+                std::swap(pools[ctype], pools.back());
             }
 
             pdata = &pools[ctype];
@@ -1745,7 +1744,6 @@ public:
     }
 
 private:
-    mutable std::size_t skip_family_pools{};
     mutable std::vector<pool_data> pools{};
     std::vector<group_data> groups{};
     std::vector<ctx_variable> vars{};