Skip to content
Snippets Groups Projects
Commit c7f78a08 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

speed improvements

parent 3c318b62
No related branches found
No related tags found
No related merge requests found
...@@ -5,3 +5,4 @@ here's only the changelog for the version in development ...@@ -5,3 +5,4 @@ here's only the changelog for the version in development
* proofed against loading empty strings * proofed against loading empty strings
* Python 3.6 is supported * Python 3.6 is supported
* minor speed improvements
...@@ -44,13 +44,13 @@ cpdef void switch_default_double(): ...@@ -44,13 +44,13 @@ cpdef void switch_default_double():
global float_encoding_mode global float_encoding_mode
float_encoding_mode = 1 float_encoding_mode = 1
cdef tuple parse_cstring(bytes data, int starting_position): cdef inline tuple parse_cstring(bytes data, int starting_position):
cdef: cdef:
int strlen = data[starting_position] int strlen = data[starting_position]
bytes subdata = data[starting_position+1:starting_position+1+strlen] bytes subdata = data[starting_position+1:starting_position+1+strlen]
return strlen+1, subdata return strlen+1, subdata
cdef tuple parse_list(bytes data, int elem_count, int starting_position): cdef inline tuple parse_list(bytes data, int elem_count, int starting_position):
""" """
Parse a list with this many elements Parse a list with this many elements
...@@ -120,8 +120,8 @@ cdef inline tuple parse_sdict(bytes data, int elem_count, int starting_position) ...@@ -120,8 +120,8 @@ cdef inline tuple parse_sdict(bytes data, int elem_count, int starting_position)
return offset, dct return offset, dct
cdef bint can_be_encoded_as_a_dict(dict dct): cdef inline bint can_be_encoded_as_a_dict(dict dct):
for key, value in dct.items(): for key in dct.keys():
if not isinstance(key, str): if not isinstance(key, str):
return False return False
if len(key) > 255: if len(key) > 255:
...@@ -167,16 +167,13 @@ cpdef tuple parse(bytes data, int starting_position): ...@@ -167,16 +167,13 @@ cpdef tuple parse(bytes data, int starting_position):
raise DecodingError('Invalid UTF-8') from e raise DecodingError('Invalid UTF-8') from e
elif value_type & 0xF0 == 0x40: elif value_type & 0xF0 == 0x40:
elements = value_type & 0xF elements = value_type & 0xF
e_list = []
string_length, e_list = parse_list(data, elements, starting_position+1) string_length, e_list = parse_list(data, elements, starting_position+1)
return string_length+1, e_list return string_length+1, e_list
elif value_type & 0xF0 == 0x50: elif value_type & 0xF0 == 0x50:
e_dict = {}
elements = value_type & 0xF elements = value_type & 0xF
offset, e_dict = parse_dict(data, elements, starting_position+1) offset, e_dict = parse_dict(data, elements, starting_position+1)
return offset+1, e_dict return offset+1, e_dict
elif value_type & 0xF0 == 0x60: elif value_type & 0xF0 == 0x60:
e_dict = {}
elements = value_type & 0xF elements = value_type & 0xF
offset, e_dict = parse_sdict(data, elements, starting_position+1) offset, e_dict = parse_sdict(data, elements, starting_position+1)
return offset+1, e_dict return offset+1, e_dict
...@@ -212,7 +209,6 @@ cpdef tuple parse(bytes data, int starting_position): ...@@ -212,7 +209,6 @@ cpdef tuple parse(bytes data, int starting_position):
return 2, sint8 return 2, sint8
elif value_type == 7: elif value_type == 7:
elements = data[starting_position+1] elements = data[starting_position+1]
e_list = []
offset, e_list = parse_list(data, elements, starting_position+2) offset, e_list = parse_list(data, elements, starting_position+2)
return offset+2, e_list return offset+2, e_list
elif value_type == 8: elif value_type == 8:
...@@ -226,7 +222,6 @@ cpdef tuple parse(bytes data, int starting_position): ...@@ -226,7 +222,6 @@ cpdef tuple parse(bytes data, int starting_position):
return 4, uint32 return 4, uint32
elif value_type == 11: elif value_type == 11:
elements = data[starting_position+1] elements = data[starting_position+1]
e_dict = {}
offset, e_dict = parse_dict(data, elements, starting_position+2) offset, e_dict = parse_dict(data, elements, starting_position+2)
return offset+2, e_dict return offset+2, e_dict
elif value_type == 13: elif value_type == 13:
......
# coding: utf-8 # coding: utf-8
[metadata] [metadata]
version = 2.1rc1 version = 2.1rc2
name = minijson name = minijson
long-description = file: README.md long-description = file: README.md
long-description-content-type = text/markdown; charset=UTF-8 long-description-content-type = text/markdown; charset=UTF-8
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment