diff --git a/src/entt/entity/registry.hpp b/src/entt/entity/registry.hpp index b09612404..e6c6c0467 100644 --- a/src/entt/entity/registry.hpp +++ b/src/entt/entity/registry.hpp @@ -155,10 +155,15 @@ template return !(lhs < rhs); } -struct registry_context { +class registry_context { + using key_type = id_type; + using mapped_type = basic_any<0u>; + using container_type = dense_map; + +public: template Type &emplace_hint(const id_type id, Args &&...args) { - return any_cast(data.try_emplace(id, std::in_place_type, std::forward(args)...).first->second); + return any_cast(ctx.try_emplace(id, std::in_place_type, std::forward(args)...).first->second); } template @@ -168,40 +173,40 @@ struct registry_context { template bool erase(const id_type id = type_id().hash()) { - const auto it = data.find(id); - return it != data.end() && it->second.type() == type_id() ? (data.erase(it), true) : false; + const auto it = ctx.find(id); + return it != ctx.end() && it->second.type() == type_id() ? (ctx.erase(it), true) : false; } template [[nodiscard]] const Type &at(const id_type id = type_id().hash()) const { - return any_cast(data.at(id)); + return any_cast(ctx.at(id)); } template [[nodiscard]] Type &at(const id_type id = type_id().hash()) { - return any_cast(data.at(id)); + return any_cast(ctx.at(id)); } template [[nodiscard]] const Type *find(const id_type id = type_id().hash()) const { - const auto it = data.find(id); - return it != data.cend() ? any_cast(&it->second) : nullptr; + const auto it = ctx.find(id); + return it != ctx.cend() ? any_cast(&it->second) : nullptr; } template [[nodiscard]] Type *find(const id_type id = type_id().hash()) { - const auto it = data.find(id); - return it != data.end() ? any_cast(&it->second) : nullptr; + const auto it = ctx.find(id); + return it != ctx.end() ? any_cast(&it->second) : nullptr; } template [[nodiscard]] bool contains(const id_type id = type_id().hash()) const { - const auto it = data.find(id); - return it != data.cend() && it->second.type() == type_id(); + const auto it = ctx.find(id); + return it != ctx.cend() && it->second.type() == type_id(); } private: - dense_map, identity> data; + container_type ctx; }; } // namespace internal