feat: speed up marshaller by pre-packing bools (#139)
This commit is contained in:
parent
4a23e0e0c5
commit
c10a241dc5
@ -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
|
||||
|
||||
@ -5,6 +5,8 @@ from ..signature import SignatureType, Variant, get_signature_tree
|
||||
|
||||
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:
|
||||
@ -34,7 +36,7 @@ class Marshaller:
|
||||
|
||||
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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user