feat: speed up marshaller by pre-packing bools (#139)
This commit is contained in:
@@ -3,9 +3,12 @@
|
|||||||
import cython
|
import cython
|
||||||
|
|
||||||
|
|
||||||
cdef bytes PACKED_UINT32_ZERO
|
|
||||||
cdef object PACK_UINT32
|
cdef object PACK_UINT32
|
||||||
|
|
||||||
|
cdef bytes PACKED_UINT32_ZERO
|
||||||
|
cdef bytes PACKED_BOOL_TRUE
|
||||||
|
cdef bytes PACKED_BOOL_FALSE
|
||||||
|
|
||||||
cdef class Marshaller:
|
cdef class Marshaller:
|
||||||
|
|
||||||
cdef object signature_tree
|
cdef object signature_tree
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ from ..signature import SignatureType, Variant, get_signature_tree
|
|||||||
|
|
||||||
PACK_UINT32 = Struct("<I").pack
|
PACK_UINT32 = Struct("<I").pack
|
||||||
PACKED_UINT32_ZERO = PACK_UINT32(0)
|
PACKED_UINT32_ZERO = PACK_UINT32(0)
|
||||||
|
PACKED_BOOL_FALSE = PACK_UINT32(int(0))
|
||||||
|
PACKED_BOOL_TRUE = PACK_UINT32(int(1))
|
||||||
|
|
||||||
|
|
||||||
class Marshaller:
|
class Marshaller:
|
||||||
@@ -34,7 +36,7 @@ class Marshaller:
|
|||||||
|
|
||||||
def write_boolean(self, boolean: bool, type_: SignatureType) -> int:
|
def write_boolean(self, boolean: bool, type_: SignatureType) -> int:
|
||||||
written = self._align(4)
|
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
|
return written + 4
|
||||||
|
|
||||||
def write_signature(self, signature: str, type_: SignatureType) -> int:
|
def write_signature(self, signature: str, type_: SignatureType) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user