From f5dbf645dbc8146775c207bd143d9b5f85595c0b Mon Sep 17 00:00:00 2001 From: m4reQ <51420351+m4reQ@users.noreply.github.com> Date: Wed, 21 Aug 2024 08:28:07 +0200 Subject: [PATCH] Remove unnecessary dictionary lookup inside `has_components` (#103) --- esper/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esper/__init__.py b/esper/__init__.py index 1def6a3..e7edae2 100644 --- a/esper/__init__.py +++ b/esper/__init__.py @@ -324,7 +324,8 @@ def has_component(entity: int, component_type: _Type[_C]) -> bool: def has_components(entity: int, *component_types: _Type[_C]) -> bool: """Check if an Entity has all the specified Component types.""" - return all(comp_type in _entities[entity] for comp_type in component_types) + components_dict = _entities[entity] + return all(comp_type in components_dict for comp_type in component_types) def add_component(entity: int, component_instance: _C, type_alias: _Optional[_Type[_C]] = None) -> None: