Skip to content

Commit

Permalink
feat: speed up unmarshaller (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Sep 12, 2023
1 parent 1996520 commit e4cae13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/dbus_fast/_private/unmarshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ cdef class Unmarshaller:

cdef _next_message(self)

cdef _has_another_message_in_buffer(self)
cdef bint _has_another_message_in_buffer(self)

@cython.locals(
msg=cython.bytes,
Expand Down Expand Up @@ -199,6 +199,7 @@ cdef class Unmarshaller:

@cython.locals(
endian=cython.uint,
buffer=cython.bytearray,
protocol_version=cython.uint,
key=cython.str,
)
Expand Down
10 changes: 5 additions & 5 deletions src/dbus_fast/_private/unmarshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,26 +622,26 @@ def _read_header(self) -> None:
):
self._is_native = 1 # pragma: no cover
self._body_len = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 4
buffer, 4
)
self._serial = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 8
buffer, 8
)
self._header_len = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 12
buffer, 12
)
elif endian == LITTLE_ENDIAN:
(
self._body_len,
self._serial,
self._header_len,
) = UNPACK_HEADER_LITTLE_ENDIAN(self._buf, 4)
) = UNPACK_HEADER_LITTLE_ENDIAN(buffer, 4)
self._uint32_unpack = UINT32_UNPACK_LITTLE_ENDIAN
self._int16_unpack = INT16_UNPACK_LITTLE_ENDIAN
self._uint16_unpack = UINT16_UNPACK_LITTLE_ENDIAN
elif endian == BIG_ENDIAN:
self._body_len, self._serial, self._header_len = UNPACK_HEADER_BIG_ENDIAN(
self._buf, 4
buffer, 4
)
self._uint32_unpack = UINT32_UNPACK_BIG_ENDIAN
self._int16_unpack = INT16_UNPACK_BIG_ENDIAN
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_fast/aio/message_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _message_reader() -> None:
try:
while True:
message = unmarshaller._unmarshall()
if not message:
if message is None:
return
try:
process(message)
Expand Down

0 comments on commit e4cae13

Please sign in to comment.