From f9b61b8bc734b0179bde2c08e46c02de65f27e50 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 13 Sep 2023 13:21:25 -0500 Subject: [PATCH] feat: speed up readers in the unmarshall path (#253) --- src/dbus_fast/_private/unmarshaller.pxd | 8 ++++---- src/dbus_fast/_private/unmarshaller.py | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/dbus_fast/_private/unmarshaller.pxd b/src/dbus_fast/_private/unmarshaller.pxd index 1147666b..f577836c 100644 --- a/src/dbus_fast/_private/unmarshaller.pxd +++ b/src/dbus_fast/_private/unmarshaller.pxd @@ -137,20 +137,20 @@ cdef class Unmarshaller: recv=cython.tuple, errno=cython.uint ) - cdef _read_sock_with_fds(self, unsigned int pos, unsigned int missing_bytes) + cdef void _read_sock_with_fds(self, unsigned int pos, unsigned int missing_bytes) @cython.locals( data=cython.bytes, errno=cython.uint ) - cdef _read_sock_without_fds(self, unsigned int pos) + cdef void _read_sock_without_fds(self, unsigned int pos) @cython.locals( data=cython.bytes ) - cdef _read_stream(self, unsigned int pos, unsigned int missing_bytes) + cdef void _read_stream(self, unsigned int pos, unsigned int missing_bytes) - cdef _read_to_pos(self, unsigned int pos) + cdef void _read_to_pos(self, unsigned int pos) cpdef read_boolean(self, SignatureType type_) diff --git a/src/dbus_fast/_private/unmarshaller.py b/src/dbus_fast/_private/unmarshaller.py index 48bbf302..833ef128 100644 --- a/src/dbus_fast/_private/unmarshaller.py +++ b/src/dbus_fast/_private/unmarshaller.py @@ -300,7 +300,7 @@ def _read_sock_with_fds(self, pos: _int, missing_bytes: _int) -> None: self._unix_fds.extend( ARRAY("i", data[: len(data) - (len(data) % MAX_UNIX_FDS_SIZE)]) ) - if msg == b"": + if not msg: raise EOFError() self._buf += msg if len(self._buf) < pos: @@ -322,7 +322,7 @@ def _read_sock_without_fds(self, pos: _int) -> None: if errno == EAGAIN or errno == EWOULDBLOCK: raise MARSHALL_STREAM_END_ERROR raise - if data == b"": + if not data: raise EOFError() self._buf += data if len(self._buf) >= pos: @@ -333,7 +333,7 @@ def _read_stream(self, pos: _int, missing_bytes: _int) -> bytes: data = self._stream_reader(missing_bytes) # type: ignore[misc] if data is None: raise MARSHALL_STREAM_END_ERROR - if data == b"": + if not data: raise EOFError() self._buf += data if len(self._buf) < pos: