Copy callbacks instead of slice for event dispatch (#109711)
We established copy is faster in https://github.com/home-assistant/core/pull/108428#discussion_r1466932262pull/109731/head
parent
8df305c881
commit
6f28d79651
|
@ -291,7 +291,7 @@ def _async_dispatch_entity_id_event(
|
||||||
"""Dispatch to listeners."""
|
"""Dispatch to listeners."""
|
||||||
if not (callbacks_list := callbacks.get(event.data["entity_id"])):
|
if not (callbacks_list := callbacks.get(event.data["entity_id"])):
|
||||||
return
|
return
|
||||||
for job in callbacks_list[:]:
|
for job in callbacks_list.copy():
|
||||||
try:
|
try:
|
||||||
hass.async_run_hass_job(job, event)
|
hass.async_run_hass_job(job, event)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
|
@ -428,7 +428,7 @@ def _async_dispatch_old_entity_id_or_entity_id_event(
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
for job in callbacks_list[:]:
|
for job in callbacks_list.copy():
|
||||||
try:
|
try:
|
||||||
hass.async_run_hass_job(job, event)
|
hass.async_run_hass_job(job, event)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
|
@ -499,7 +499,7 @@ def _async_dispatch_device_id_event(
|
||||||
"""Dispatch to listeners."""
|
"""Dispatch to listeners."""
|
||||||
if not (callbacks_list := callbacks.get(event.data["device_id"])):
|
if not (callbacks_list := callbacks.get(event.data["device_id"])):
|
||||||
return
|
return
|
||||||
for job in callbacks_list[:]:
|
for job in callbacks_list.copy():
|
||||||
try:
|
try:
|
||||||
hass.async_run_hass_job(job, event)
|
hass.async_run_hass_job(job, event)
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
|
|
Loading…
Reference in New Issue