Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 47d3c7a

Browse filesBrowse files
authored
feat: speed up the service registry with a cython pxd (#1226)
1 parent cd7b56b commit 47d3c7a
Copy full SHA for 47d3c7a

File tree

3 files changed

+23
-1
lines changed
Filter options

3 files changed

+23
-1
lines changed

‎build_ext.py

Copy file name to clipboardExpand all lines: build_ext.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def build(setup_kwargs: Any) -> None:
2828
"src/zeroconf/_listener.py",
2929
"src/zeroconf/_protocol/incoming.py",
3030
"src/zeroconf/_protocol/outgoing.py",
31+
"src/zeroconf/_services/registry.py",
3132
],
3233
compiler_directives={"language_level": "3"}, # Python 3
3334
),

‎src/zeroconf/_services/registry.pxd

Copy file name to clipboard
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import cython
3+
4+
5+
cdef class ServiceRegistry:
6+
7+
cdef cython.dict _services
8+
cdef public cython.dict types
9+
cdef public cython.dict servers
10+
11+
@cython.locals(
12+
record_list=cython.list,
13+
)
14+
cdef _async_get_by_index(self, cython.dict records, str key)
15+
16+
cdef _add(self, object info)
17+
18+
cdef _remove(self, cython.list infos)

‎src/zeroconf/_services/registry.py

Copy file name to clipboardExpand all lines: src/zeroconf/_services/registry.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ def async_get_infos_server(self, server: str) -> List[ServiceInfo]:
7878

7979
def _async_get_by_index(self, records: Dict[str, List], key: str) -> List[ServiceInfo]:
8080
"""Return all ServiceInfo matching the index."""
81-
return [self._services[name] for name in records.get(key, [])]
81+
record_list = records.get(key)
82+
if record_list is None:
83+
return []
84+
return [self._services[name] for name in record_list]
8285

8386
def _add(self, info: ServiceInfo) -> None:
8487
"""Add a new service under the lock."""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.