Skip to content

Commit

Permalink
feat: improve unmarshall performance (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Apr 21, 2023
1 parent 5d55022 commit 3dc98be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
25 changes: 14 additions & 11 deletions src/dbus_fast/_private/unmarshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ cdef object UINT16_UNPACK_BIG_ENDIAN

cdef cython.dict MESSAGE_TYPE_MAP
cdef cython.dict MESSAGE_FLAG_MAP
cdef object HEADER_MESSAGE_ARG_NAME
cdef dict HEADER_MESSAGE_ARG_NAME

cdef SignatureTree SIGNATURE_TREE_EMPTY
cdef SignatureTree SIGNATURE_TREE_B
Expand Down Expand Up @@ -108,8 +108,8 @@ cdef class Unmarshaller:
cdef unsigned int _body_len
cdef unsigned int _serial
cdef unsigned int _header_len
cdef unsigned int _message_type
cdef unsigned int _flag
cdef object _message_type
cdef object _flag
cdef unsigned int _msg_len
cdef unsigned int _is_native
cdef object _uint32_unpack
Expand Down Expand Up @@ -154,9 +154,12 @@ cdef class Unmarshaller:
@cython.locals(
str_start=cython.uint,
)
cdef _read_string_unpack(self)
cdef str _read_string_unpack(self)

cdef _read_variant(self)
@cython.locals(
tree=SignatureTree,
)
cdef Variant _read_variant(self)

cpdef read_array(self, SignatureType type_)

Expand All @@ -165,25 +168,26 @@ cdef class Unmarshaller:
array_length=cython.uint,
child_type=SignatureType,
)
cdef _read_array(self, SignatureType type_)
cdef object _read_array(self, SignatureType type_)

cpdef read_signature(self, SignatureType type_)

@cython.locals(
o=cython.ulong,
signature_len=cython.uint,
)
cdef _read_signature(self)
cdef str _read_signature(self)

@cython.locals(
endian=cython.uint,
protocol_version=cython.uint,
key=cython.str
key=cython.str,
)
cdef _read_header(self)

@cython.locals(
body=cython.list
body=cython.list,
header_fields=cython.dict
)
cdef _read_body(self)

Expand All @@ -194,8 +198,7 @@ cdef class Unmarshaller:
@cython.locals(
beginning_pos=cython.ulong,
o=cython.ulong,
field_0=cython.uint,
token_as_int=cython.uint,
signature_len=cython.uint,
)
cdef header_fields(self, unsigned int header_length)
cdef cython.dict _header_fields(self, unsigned int header_length)
4 changes: 2 additions & 2 deletions src/dbus_fast/_private/unmarshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def _read_array(self, type_: _SignatureType) -> Iterable[Any]:
result_list.append(reader(self, child_type))
return result_list

def header_fields(self, header_length: int) -> Dict[str, Any]:
def _header_fields(self, header_length: int) -> Dict[str, Any]:
"""Header fields are always a(yv)."""
beginning_pos = self._pos
headers = {}
Expand Down Expand Up @@ -586,7 +586,7 @@ def _read_body(self) -> None:
"""Read the body of the message."""
self._read_to_pos(HEADER_SIGNATURE_SIZE + self._msg_len)
self._pos = HEADER_ARRAY_OF_STRUCT_SIGNATURE_POSITION
header_fields = self.header_fields(self._header_len)
header_fields = self._header_fields(self._header_len)
self._pos += -self._pos & 7 # align 8
header_fields.pop("unix_fds", None) # defined by self._unix_fds
signature = header_fields.pop("signature", "")
Expand Down

0 comments on commit 3dc98be

Please sign in to comment.