feat: speed up unmarshaller (#250)

This commit is contained in:
J. Nick Koston 2023-09-11 21:43:34 -05:00 committed by GitHub
parent 1996520489
commit e4cae13e1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -130,7 +130,7 @@ cdef class Unmarshaller:
cdef _next_message(self)
cdef _has_another_message_in_buffer(self)
cdef bint _has_another_message_in_buffer(self)
@cython.locals(
msg=cython.bytes,
@ -199,6 +199,7 @@ cdef class Unmarshaller:
@cython.locals(
endian=cython.uint,
buffer=cython.bytearray,
protocol_version=cython.uint,
key=cython.str,
)

View File

@ -622,26 +622,26 @@ class Unmarshaller:
):
self._is_native = 1 # pragma: no cover
self._body_len = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 4
buffer, 4
)
self._serial = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 8
buffer, 8
)
self._header_len = _cast_uint32_native( # type: ignore[name-defined] # pragma: no cover
self._buf, 12
buffer, 12
)
elif endian == LITTLE_ENDIAN:
(
self._body_len,
self._serial,
self._header_len,
) = UNPACK_HEADER_LITTLE_ENDIAN(self._buf, 4)
) = UNPACK_HEADER_LITTLE_ENDIAN(buffer, 4)
self._uint32_unpack = UINT32_UNPACK_LITTLE_ENDIAN
self._int16_unpack = INT16_UNPACK_LITTLE_ENDIAN
self._uint16_unpack = UINT16_UNPACK_LITTLE_ENDIAN
elif endian == BIG_ENDIAN:
self._body_len, self._serial, self._header_len = UNPACK_HEADER_BIG_ENDIAN(
self._buf, 4
buffer, 4
)
self._uint32_unpack = UINT32_UNPACK_BIG_ENDIAN
self._int16_unpack = INT16_UNPACK_BIG_ENDIAN

View File

@ -20,7 +20,7 @@ def build_message_reader(
try:
while True:
message = unmarshaller._unmarshall()
if not message:
if message is None:
return
try:
process(message)