Skip to content

Commit

Permalink
Speed up GameObjectManager::get_singleton_by_type
Browse files Browse the repository at this point in the history
It had been scanning through the full list of objects, instead of
looking up the singleton in m_objects_by_type_index.
  • Loading branch information
mstoeckl committed Jun 24, 2024
1 parent aa6444d commit f6b5bde
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/supertux/game_object_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ class GameObjectManager
template<class T>
T& get_singleton_by_type() const
{
const auto& range = get_objects_by_type<T>();
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<T*>(objs[0]);
assert(obj->is_singleton());
return *obj;
}

template<class T>
Expand Down

0 comments on commit f6b5bde

Please sign in to comment.