feat: speed up decoding headers by avoiding unicode checks (#125)
This commit is contained in:
@@ -61,6 +61,10 @@ cdef object SIGNATURE_TREE_AY_TYPES_0
|
|||||||
cdef object SIGNATURE_TREE_A_QV
|
cdef object SIGNATURE_TREE_A_QV
|
||||||
cdef object SIGNATURE_TREE_A_QV_TYPES_0
|
cdef object SIGNATURE_TREE_A_QV_TYPES_0
|
||||||
|
|
||||||
|
cdef unsigned int TOKEN_O_AS_INT
|
||||||
|
cdef unsigned int TOKEN_S_AS_INT
|
||||||
|
cdef unsigned int TOKEN_G_AS_INT
|
||||||
|
|
||||||
|
|
||||||
cpdef get_signature_tree
|
cpdef get_signature_tree
|
||||||
|
|
||||||
@@ -170,6 +174,7 @@ cdef class Unmarshaller:
|
|||||||
beginning_pos=cython.ulong,
|
beginning_pos=cython.ulong,
|
||||||
o=cython.ulong,
|
o=cython.ulong,
|
||||||
field_0=cython.uint,
|
field_0=cython.uint,
|
||||||
|
token_as_int=cython.uint,
|
||||||
signature_len=cython.uint,
|
signature_len=cython.uint,
|
||||||
)
|
)
|
||||||
cdef header_fields(self, unsigned int header_length)
|
cdef header_fields(self, unsigned int header_length)
|
||||||
|
|||||||
@@ -84,6 +84,10 @@ SIGNATURE_TREE_SA_SV_AS_TYPES_2 = SIGNATURE_TREE_SA_SV_AS.types[2]
|
|||||||
SIGNATURE_TREE_OA_SA_SV = get_signature_tree("oa{sa{sv}}")
|
SIGNATURE_TREE_OA_SA_SV = get_signature_tree("oa{sa{sv}}")
|
||||||
SIGNATURE_TREE_OA_SA_SV_TYPES_1 = SIGNATURE_TREE_OA_SA_SV.types[1]
|
SIGNATURE_TREE_OA_SA_SV_TYPES_1 = SIGNATURE_TREE_OA_SA_SV.types[1]
|
||||||
|
|
||||||
|
TOKEN_O_AS_INT = ord("o")
|
||||||
|
TOKEN_S_AS_INT = ord("s")
|
||||||
|
TOKEN_G_AS_INT = ord("g")
|
||||||
|
|
||||||
HEADER_MESSAGE_ARG_NAME = {
|
HEADER_MESSAGE_ARG_NAME = {
|
||||||
1: "path",
|
1: "path",
|
||||||
2: "interface",
|
2: "interface",
|
||||||
@@ -483,16 +487,17 @@ 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'
|
||||||
token = buf[o : o + signature_len].decode()
|
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_MESSAGE_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 in "os":
|
if token_as_int == TOKEN_O_AS_INT or token_as_int == TOKEN_S_AS_INT:
|
||||||
headers[key] = self._read_string_unpack()
|
headers[key] = self._read_string_unpack()
|
||||||
elif token == "g":
|
elif token_as_int == TOKEN_G_AS_INT:
|
||||||
headers[key] = self._read_signature()
|
headers[key] = self._read_signature()
|
||||||
else:
|
else:
|
||||||
|
token = buf[o : o + signature_len].decode()
|
||||||
# There shouldn't be any other types in the header
|
# There shouldn't be any other types in the header
|
||||||
# but just in case, we'll read it using the slow path
|
# but just in case, we'll read it using the slow path
|
||||||
headers[key] = readers[token](self, get_signature_tree(token).types[0])
|
headers[key] = readers[token](self, get_signature_tree(token).types[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user