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 d97bc78

Browse filesBrowse files
committed
chore: benchmark string slicing options
`__Pyx_PyBytes_AsString` -> `__Pyx_PyBytes_FromStringAndSize` seems to be significantly faster than `PySequence_GetSlice`
1 parent 89e3cbd commit d97bc78
Copy full SHA for d97bc78

File tree

2 files changed

+8
-2
lines changed
Filter options

2 files changed

+8
-2
lines changed

‎src/zeroconf/_protocol/incoming.pxd

Copy file name to clipboardExpand all lines: src/zeroconf/_protocol/incoming.pxd
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ cdef class DNSIncoming:
102102

103103
@cython.locals(
104104
length="unsigned int",
105+
cstr="const unsigned char *"
105106
)
106107
cdef str _read_character_string(self)
107108

109+
@cython.locals(
110+
cstr="const unsigned char *"
111+
)
108112
cdef bytes _read_string(self, unsigned int length)
109113

110114
@cython.locals(

‎src/zeroconf/_protocol/incoming.py

Copy file name to clipboardExpand all lines: src/zeroconf/_protocol/incoming.py
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,15 @@ def _read_character_string(self) -> str:
260260
"""Reads a character string from the packet"""
261261
length = self.view[self.offset]
262262
self.offset += 1
263-
info = self.data[self.offset : self.offset + length].decode("utf-8", "replace")
263+
cstr = self.data
264+
info = cstr[self.offset : self.offset + length].decode("utf-8", "replace")
264265
self.offset += length
265266
return info
266267

267268
def _read_string(self, length: _int) -> bytes:
268269
"""Reads a string of a given length from the packet"""
269-
info = self.data[self.offset : self.offset + length]
270+
cstr = self.data
271+
info = cstr[self.offset : self.offset + length]
270272
self.offset += length
271273
return info
272274

0 commit comments

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