diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index 22dd05e03..3055ef24b 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -382,29 +382,26 @@ public: } /** - * @brief Increases the capacity of the pool for the given component. + * @brief Increases the capacity of the registry or of the pools for the + * given components. * - * If the new capacity is greater than the current capacity, new storage is - * allocated, otherwise the method does nothing. + * If no components are specified, the capacity of the registry is + * increased, that is the number of entities it contains. Otherwise the + * capacity of the pools for the given components is increased. * - * @tparam Component Type of component for which to reserve storage. + * In both cases, if the new capacity is greater than the current capacity, + * new storage is allocated, otherwise the method does nothing. + * + * @tparam Component Types of components for which to reserve storage. * @param cap Desired capacity. */ - template + template void reserve(const size_type cap) { - assure()->reserve(cap); - } - - /** - * @brief Increases the capacity of a registry in terms of entities. - * - * If the new capacity is greater than the current capacity, new storage is - * allocated, otherwise the method does nothing. - * - * @param cap Desired capacity. - */ - void reserve(const size_type cap) { - entities.reserve(cap); + if constexpr(sizeof...(Component) == 0) { + entities.reserve(cap); + } else { + (assure()->reserve(cap), ...); + } } /** diff --git a/test/entt/entity/registry.cpp b/test/entt/entity/registry.cpp index 78373b3e7..3a54071a3 100644 --- a/test/entt/entity/registry.cpp +++ b/test/entt/entity/registry.cpp @@ -90,9 +90,8 @@ TEST(Registry, Functionalities) { ASSERT_EQ(registry.size(), entt::registry::size_type{0}); ASSERT_EQ(registry.alive(), entt::registry::size_type{0}); + ASSERT_NO_THROW((registry.reserve(8))); ASSERT_NO_THROW(registry.reserve(42)); - ASSERT_NO_THROW(registry.reserve(8)); - ASSERT_NO_THROW(registry.reserve(8)); ASSERT_TRUE(registry.empty()); ASSERT_EQ(registry.capacity(), entt::registry::size_type{42});