From 95d8370da44a0cd574ab8599de191ac07293918e Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 6 Mar 2024 14:25:05 +0100 Subject: [PATCH] sparse_set: shared policy_to_head function --- src/entt/entity/sparse_set.hpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index 42ada24d5..37719dbec 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/src/entt/entity/sparse_set.hpp @@ -132,6 +132,11 @@ template return !(lhs < rhs); } +template +auto policy_to_head(const Type mask, const deletion_policy mode) noexcept { + return mask * (mode != deletion_policy::swap_only); +} + } // namespace internal /*! @endcond */ @@ -218,10 +223,6 @@ class basic_sparse_set { std::swap(lhs, rhs); } - underlying_type policy_to_head() const noexcept { - return traits_type::entity_mask * (mode != deletion_policy::swap_only); - } - private: virtual const void *get_at(const std::size_t) const { return nullptr; @@ -320,7 +321,7 @@ protected: break; } - head = policy_to_head(); + head = internal::policy_to_head(traits_type::entity_mask, mode); packed.clear(); } @@ -420,7 +421,7 @@ public: packed{allocator}, info{&elem}, mode{pol}, - head{policy_to_head()} { + head{internal::policy_to_head(traits_type::entity_mask, mode)} { ENTT_ASSERT(traits_type::version_mask || mode != deletion_policy::in_place, "Policy does not support zero-sized versions"); } @@ -433,7 +434,7 @@ public: packed{std::move(other.packed)}, info{other.info}, mode{other.mode}, - head{std::exchange(other.head, policy_to_head())} {} + head{std::exchange(other.head, internal::policy_to_head(traits_type::entity_mask, mode))} {} /** * @brief Allocator-extended move constructor. @@ -445,7 +446,7 @@ public: packed{std::move(other.packed), allocator}, info{other.info}, mode{other.mode}, - head{std::exchange(other.head, policy_to_head())} { + head{std::exchange(other.head, internal::policy_to_head(traits_type::entity_mask, mode))} { ENTT_ASSERT(alloc_traits::is_always_equal::value || packed.get_allocator() == other.packed.get_allocator(), "Copying a sparse set is not allowed"); } @@ -467,7 +468,7 @@ public: packed = std::move(other.packed); info = other.info; mode = other.mode; - head = std::exchange(other.head, policy_to_head()); + head = std::exchange(other.head, internal::policy_to_head(traits_type::entity_mask, mode)); return *this; } @@ -1064,7 +1065,7 @@ public: pop_all(); // sanity check to avoid subtle issues due to storage classes ENTT_ASSERT((compact(), size()) == 0u, "Non-empty set"); - head = policy_to_head(); + head = internal::policy_to_head(traits_type::entity_mask, mode); packed.clear(); }