Copy callbacks instead of slice for event dispatch (#109711)

We established copy is faster in
https://github.com/home-assistant/core/pull/108428#discussion_r1466932262
This commit is contained in:
J. Nick Koston 2024-02-05 10:07:21 -06:00 committed by GitHub
parent 8df305c881
commit 6f28d79651
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -291,7 +291,7 @@ def _async_dispatch_entity_id_event(
"""Dispatch to listeners."""
if not (callbacks_list := callbacks.get(event.data["entity_id"])):
return
for job in callbacks_list[:]:
for job in callbacks_list.copy():
try:
hass.async_run_hass_job(job, event)
except Exception: # pylint: disable=broad-except
@ -428,7 +428,7 @@ def _async_dispatch_old_entity_id_or_entity_id_event(
)
):
return
for job in callbacks_list[:]:
for job in callbacks_list.copy():
try:
hass.async_run_hass_job(job, event)
except Exception: # pylint: disable=broad-except
@ -499,7 +499,7 @@ def _async_dispatch_device_id_event(
"""Dispatch to listeners."""
if not (callbacks_list := callbacks.get(event.data["device_id"])):
return
for job in callbacks_list[:]:
for job in callbacks_list.copy():
try:
hass.async_run_hass_job(job, event)
except Exception: # pylint: disable=broad-except