From f6b5bde7f735bfb1da2d847226e3ef82c4c20c1f 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..82bfc9f5bad 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 = static_cast(objs[0]); + assert(obj->is_singleton()); + return *obj; } template