Skip to content

Commit

Permalink
feat: speed up marshaller by pre-packing bools (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Nov 3, 2022
1 parent 4a23e0e commit c10a241
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/dbus_fast/_private/marshaller.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import cython


cdef bytes PACKED_UINT32_ZERO
cdef object PACK_UINT32

cdef bytes PACKED_UINT32_ZERO
cdef bytes PACKED_BOOL_TRUE
cdef bytes PACKED_BOOL_FALSE

cdef class Marshaller:

cdef object signature_tree
Expand Down
4 changes: 3 additions & 1 deletion src/dbus_fast/_private/marshaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

PACK_UINT32 = Struct("<I").pack
PACKED_UINT32_ZERO = PACK_UINT32(0)
PACKED_BOOL_FALSE = PACK_UINT32(int(0))
PACKED_BOOL_TRUE = PACK_UINT32(int(1))


class Marshaller:
Expand Down Expand Up @@ -34,7 +36,7 @@ def _align(self, n):

def write_boolean(self, boolean: bool, type_: SignatureType) -> int:
written = self._align(4)
self._buf.extend(PACK_UINT32(int(boolean)))
self._buf += PACKED_BOOL_TRUE if boolean else PACKED_BOOL_FALSE
return written + 4

def write_signature(self, signature: str, type_: SignatureType) -> int:
Expand Down

0 comments on commit c10a241

Please sign in to comment.