From e1836b2034ca4bfbb004027f98b42c68f6c6edce Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 27 Oct 2022 10:47:42 -0500 Subject: [PATCH] feat: speed up unmarshall (#114) --- src/dbus_fast/_private/unmarshaller.pxd | 4 +--- src/dbus_fast/_private/unmarshaller.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/dbus_fast/_private/unmarshaller.pxd b/src/dbus_fast/_private/unmarshaller.pxd index de7e01ee..f475c4bf 100644 --- a/src/dbus_fast/_private/unmarshaller.pxd +++ b/src/dbus_fast/_private/unmarshaller.pxd @@ -73,10 +73,8 @@ cdef class Unmarshaller: cpdef read_string_unpack(self, object type_) - cdef _read_string_unpack(self) - @cython.locals( - buf_bytes=cython.bytearray, + str_start=cython.uint, ) cdef _read_string_unpack(self) diff --git a/src/dbus_fast/_private/unmarshaller.py b/src/dbus_fast/_private/unmarshaller.py index 86abdadc..c3ae5443 100644 --- a/src/dbus_fast/_private/unmarshaller.py +++ b/src/dbus_fast/_private/unmarshaller.py @@ -267,15 +267,17 @@ def read_variant(self, type_: SignatureType) -> Variant: return self._read_variant() def _read_variant(self) -> Variant: - tree = get_signature_tree(self._read_signature()) - signature_type = tree.types[0] + signature = self._read_signature() # verify in Variant is only useful on construction not unmarshalling - token = signature_type.token - if token == "n": - return Variant(tree, self._read_int16_unpack(), False) + if signature == "n": + return Variant( + get_signature_tree(signature), self._read_int16_unpack(), False + ) + tree = get_signature_tree(signature) + signature_type = tree.types[0] return Variant( tree, - self._readers[token](self, signature_type), + self._readers[signature_type.token](self, signature_type), False, )