From fa9ebb062cf122bb88fe62874dfe73a3fb26a3ee Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 28 May 2024 16:49:58 -1000 Subject: [PATCH] Small speed up to connecting dispatchers (#118342) --- homeassistant/helpers/dispatcher.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/homeassistant/helpers/dispatcher.py b/homeassistant/helpers/dispatcher.py index 43d9fb7b437..173e441781c 100644 --- a/homeassistant/helpers/dispatcher.py +++ b/homeassistant/helpers/dispatcher.py @@ -2,6 +2,7 @@ from __future__ import annotations +from collections import defaultdict from collections.abc import Callable, Coroutine from functools import partial import logging @@ -114,13 +115,8 @@ def async_dispatcher_connect[*_Ts]( This method must be run in the event loop. """ if DATA_DISPATCHER not in hass.data: - hass.data[DATA_DISPATCHER] = {} - + hass.data[DATA_DISPATCHER] = defaultdict(dict) dispatchers: _DispatcherDataType[*_Ts] = hass.data[DATA_DISPATCHER] - - if signal not in dispatchers: - dispatchers[signal] = {} - dispatchers[signal][target] = None # Use a partial for the remove since it uses # less memory than a full closure since a partial copies