registry: ctor that reserves enough memory for count pools

This commit is contained in:
Michele Caini
2022-04-08 09:58:05 +02:00
parent c553835228
commit 4e13529adb
2 changed files with 35 additions and 5 deletions

View File

@@ -333,7 +333,25 @@ public:
using context = internal::registry_context;
/*! @brief Default constructor. */
basic_registry() = default;
basic_registry()
: pools{},
groups{},
entities{},
free_list{tombstone},
vars{} {}
/**
* @brief Allocates enough memory upon construction to store `count` pools.
* @param count The number of pools to allocate memory for.
*/
basic_registry(const size_type count)
: pools{},
groups{},
entities{},
free_list{tombstone},
vars{} {
pools.reserve(count);
}
/**
* @brief Move constructor.
@@ -1465,10 +1483,10 @@ public:
}
private:
dense_map<id_type, std::unique_ptr<base_type>, identity> pools{};
std::vector<group_data> groups{};
std::vector<entity_type> entities{};
entity_type free_list{tombstone};
dense_map<id_type, std::unique_ptr<base_type>, identity> pools;
std::vector<group_data> groups;
std::vector<entity_type> entities;
entity_type free_list;
context vars;
};

View File

@@ -337,6 +337,18 @@ TEST(Registry, Functionalities) {
ASSERT_TRUE(registry.storage<int>().empty());
}
TEST(Registry, Constructors) {
entt::registry registry;
entt::registry other{42};
const entt::entity entity = entt::tombstone;
ASSERT_TRUE(registry.empty());
ASSERT_TRUE(other.empty());
ASSERT_EQ(registry.released(), entity);
ASSERT_EQ(other.released(), entity);
}
TEST(Registry, Move) {
entt::registry registry;
const auto entity = registry.create();