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