From 7ab5931fe199b78224e045d65d328d42526073a2 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 2 Nov 2022 20:19:48 +0100 Subject: [PATCH] Speed up marshall write_string and write_variant Added some additional cython typing --- src/dbus_fast/_private/marshaller.pxd | 4 +++- src/dbus_fast/_private/marshaller.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dbus_fast/_private/marshaller.pxd b/src/dbus_fast/_private/marshaller.pxd index 7ac3aaf0..6e736aea 100644 --- a/src/dbus_fast/_private/marshaller.pxd +++ b/src/dbus_fast/_private/marshaller.pxd @@ -24,7 +24,7 @@ cdef class Marshaller: signature_len=cython.uint, written=cython.uint, ) - cpdef write_string(self, object value, object _type) + cpdef write_string(self, str value, object _type) @cython.locals( signature_len=cython.uint, @@ -56,6 +56,8 @@ cdef class Marshaller: @cython.locals( written=cython.uint, + signature=cython.str, + signature_bytes=cython.bytes, ) cpdef write_variant(self, object variant, object type) diff --git a/src/dbus_fast/_private/marshaller.py b/src/dbus_fast/_private/marshaller.py index 3118900b..13198e80 100644 --- a/src/dbus_fast/_private/marshaller.py +++ b/src/dbus_fast/_private/marshaller.py @@ -61,7 +61,9 @@ def write_string(self, value, type_: SignatureType) -> int: return written def write_variant(self, variant: Variant, type_: SignatureType) -> int: - written = self._write_signature(variant.signature.encode()) + signature = variant.signature + signature_bytes = signature.encode() + written = self._write_signature(signature_bytes) written += self._write_single(variant.type, variant.value) return written