From e4cae13e1a25356437658a03ee60522a68a56d56 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 11 Sep 2023 21:43:34 -0500 Subject: [PATCH] feat: speed up unmarshaller (#250) --- src/dbus_fast/_private/unmarshaller.pxd | 3 ++- src/dbus_fast/_private/unmarshaller.py | 10 +++++----- src/dbus_fast/aio/message_reader.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dbus_fast/_private/unmarshaller.pxd b/src/dbus_fast/_private/unmarshaller.pxd index 516ecb2c..1147666b 100644 --- a/src/dbus_fast/_private/unmarshaller.pxd +++ b/src/dbus_fast/_private/unmarshaller.pxd @@ -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, @@ -199,6 +199,7 @@ cdef class Unmarshaller: @cython.locals( endian=cython.uint, + buffer=cython.bytearray, protocol_version=cython.uint, key=cython.str, ) diff --git a/src/dbus_fast/_private/unmarshaller.py b/src/dbus_fast/_private/unmarshaller.py index a6307229..48bbf302 100644 --- a/src/dbus_fast/_private/unmarshaller.py +++ b/src/dbus_fast/_private/unmarshaller.py @@ -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 diff --git a/src/dbus_fast/aio/message_reader.py b/src/dbus_fast/aio/message_reader.py index 6024d9c9..38460beb 100644 --- a/src/dbus_fast/aio/message_reader.py +++ b/src/dbus_fast/aio/message_reader.py @@ -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)