feat: speed up unmarshalling by skipping unused unix_fds header (#246)
This commit is contained in:
parent
5583a2a2e7
commit
5f5a150ca0
@ -22,6 +22,8 @@ cdef unsigned int HEADER_SIGNATURE_SIZE
|
||||
cdef unsigned int LITTLE_ENDIAN
|
||||
cdef unsigned int BIG_ENDIAN
|
||||
cdef unsigned int PROTOCOL_VERSION
|
||||
cdef unsigned int HEADER_UNIX_FDS_IDX
|
||||
cdef cython.list HEADER_IDX_TO_ARG_NAME
|
||||
|
||||
cdef str UINT32_CAST
|
||||
cdef str INT16_CAST
|
||||
|
||||
@ -108,18 +108,19 @@ SCM_RIGHTS = socket.SCM_RIGHTS
|
||||
EAGAIN = errno.EAGAIN
|
||||
EWOULDBLOCK = errno.EWOULDBLOCK
|
||||
|
||||
|
||||
HEADER_MESSAGE_ARG_NAME = {
|
||||
1: "path",
|
||||
2: "interface",
|
||||
3: "member",
|
||||
4: "error_name",
|
||||
5: "reply_serial",
|
||||
6: "destination",
|
||||
7: "sender",
|
||||
8: "signature",
|
||||
9: "unix_fds",
|
||||
}
|
||||
HEADER_IDX_TO_ARG_NAME = [
|
||||
"",
|
||||
"path",
|
||||
"interface",
|
||||
"member",
|
||||
"error_name",
|
||||
"reply_serial",
|
||||
"destination",
|
||||
"sender",
|
||||
"signature",
|
||||
"unix_fds",
|
||||
]
|
||||
HEADER_UNIX_FDS_IDX = HEADER_IDX_TO_ARG_NAME.index("unix_fds")
|
||||
|
||||
_SignatureType = SignatureType
|
||||
_int = int
|
||||
@ -581,9 +582,11 @@ class Unmarshaller:
|
||||
signature_len = buf[self._pos] # byte
|
||||
o = self._pos + 1
|
||||
self._pos += signature_len + 2 # one for the byte, one for the '\0'
|
||||
if field_0 == HEADER_UNIX_FDS_IDX: # defined by self._unix_fds
|
||||
continue
|
||||
token_as_int = buf[o]
|
||||
# Now that we have the token we can read the variant value
|
||||
key = HEADER_MESSAGE_ARG_NAME[field_0]
|
||||
key = HEADER_IDX_TO_ARG_NAME[field_0]
|
||||
# Strings and signatures are the most common types
|
||||
# so we inline them for performance
|
||||
if token_as_int == TOKEN_O_AS_INT or token_as_int == TOKEN_S_AS_INT:
|
||||
@ -661,7 +664,6 @@ class Unmarshaller:
|
||||
self._pos = HEADER_ARRAY_OF_STRUCT_SIGNATURE_POSITION
|
||||
header_fields = self._header_fields(self._header_len)
|
||||
self._pos += -self._pos & 7 # align 8
|
||||
header_fields.pop("unix_fds", None) # defined by self._unix_fds
|
||||
signature = header_fields.pop("signature", "")
|
||||
if not self._body_len:
|
||||
tree = SIGNATURE_TREE_EMPTY
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user