Reduce the call count to eval. This reduce by 3 the time of fast(q|a)
header processing
This commit is contained in:
@ -8,13 +8,38 @@ Created on 25 mars 2016
|
|||||||
|
|
||||||
import re
|
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):
|
cdef object __etag__(str x):
|
||||||
try:
|
if __re_int__.match(x):
|
||||||
v = eval(x,{},{})
|
v=int(x)
|
||||||
except:
|
elif __re_float__.match(x):
|
||||||
v = 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
|
return v
|
||||||
|
|
||||||
cpdef tuple parseHeader(str header):
|
cpdef tuple parseHeader(str header):
|
||||||
|
Reference in New Issue
Block a user