Skip to content

Commit

Permalink
Speed up ssdp domain matching (#124842)
Browse files Browse the repository at this point in the history
* Speed up ssdp domain matching

Switch all() expression to dict.items() <= dict.items()

* rewrite as setcomp
  • Loading branch information
bdraco authored Aug 30, 2024
1 parent 69a9aa4 commit 6781a76
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions homeassistant/components/ssdp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,13 @@ def async_setup(
def async_matching_domains(self, info_with_desc: CaseInsensitiveDict) -> set[str]:
"""Find domains matching the passed CaseInsensitiveDict."""
assert self._match_by_key is not None
domains = set()
for key, matchers_by_key in self._match_by_key.items():
if not (match_value := info_with_desc.get(key)):
continue
for domain, matcher in matchers_by_key.get(match_value, []):
if domain in domains:
continue
if all(info_with_desc.get(k) == v for (k, v) in matcher.items()):
domains.add(domain)
return domains
return {
domain
for key, matchers_by_key in self._match_by_key.items()
if (match_value := info_with_desc.get(key))
for domain, matcher in matchers_by_key.get(match_value, ())
if info_with_desc.items() >= matcher.items()
}


class Scanner:
Expand Down

0 comments on commit 6781a76

Please sign in to comment.