Reduce the call count to eval. This reduce by 3 the time of fast(q|a)

header processing
This commit is contained in:
2016-04-01 08:54:06 +02:00
parent ce6ea89c21
commit efc4a4a3c6

View File

@ -8,13 +8,38 @@ Created on 25 mars 2016
import re
__ret__ = re.compile('''(([^ ]+)=('[^']*'|"[^"]*"|[^;]+); *)+?''')
__ret__ = re.compile('''(([^ ]+)=('[^']*'|"[^"]*"|[^;]+); *)+?''')
__re_int__ = re.compile("^[+-]?[0-9]+$")
__re_float__ = re.compile("^[+-]?[0-9]+(\.[0-9]*)?([eE][+-]?[0-9]+)?$")
__re_str__ = re.compile("""^"[^"]*"|'[^']*'$""")
__re_dict__ = re.compile("""^\{\ *
(
("[^"]*"|'[^']*')
\ *:\ *
([^,}]+|
"[^"]*"|
'[^']*'
)
)?
(\ *,\ *
("[^"]*"|'[^']*')
\ *:\ *
([^,}]+|
"[^"]*"|
'[^']*'
)
)*\ *\}$""", re.VERBOSE)
cdef object __etag__(str x):
try:
v = eval(x,{},{})
except:
v = x
if __re_int__.match(x):
v=int(x)
elif __re_float__.match(x):
v=float(x)
elif __re_str__.match(x):
v=x[1:-1]
elif __re_dict__.match(x):
v=eval(x)
else:
v=x
return v
cpdef tuple parseHeader(str header):