From 117d76932d324fbe8b8a91a2e86c388f49aedff2 Mon Sep 17 00:00:00 2001 From: M Stoeckl Date: Mon, 24 Jun 2024 07:58:21 -0400 Subject: [PATCH] Speed up GameObjectManager::get_singleton_by_type It had been scanning through the full list of objects, instead of looking up the singleton in m_objects_by_type_index. --- src/supertux/game_object_manager.hpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/supertux/game_object_manager.hpp b/src/supertux/game_object_manager.hpp index 4fcd6f775a4..016913fc342 100644 --- a/src/supertux/game_object_manager.hpp +++ b/src/supertux/game_object_manager.hpp @@ -116,10 +116,11 @@ class GameObjectManager template T& get_singleton_by_type() const { - const auto& range = get_objects_by_type(); - assert(range.begin() != range.end()); - assert(range.begin()->is_singleton()); - return *range.begin(); + const auto& objs = get_objects_by_type_index(typeid(T)); + assert(objs.size() == 1); + T* obj = dynamic_cast(objs[0]); + assert(obj); + return *obj; } template