• Kirill Smelkov's avatar
    golang, strconv: Switch them to cimport each other at pyx level · 533bd30a
    Kirill Smelkov authored
    Since 50b8cb7e (strconv: Move functionality related to UTF8
    encode/decode into _golang_str) both golang_str and strconv import each
    other.
    
    Before this patch that import was done at py level at runtime from
    outside to workaround the import cycle. This results in that strconv
    functionality is not available while golang is only being imported.
    So far it was not a problem, but when builtin string types will become
    patched with bstr and ustr, that will become a problem because string
    repr starts to be used at import time, which for pybstr is implemented
    via strconv.quote .
    
    -> Fix this by switching golang and strconv to cimport each other at pyx
    level. There, similarly to C, the cycle works just ok out of the box.
    
    This also automatically helps performance a bit:
    
        name                 old time/op  new time/op  delta
        quote[a]              805µs ± 0%   786µs ± 1%   -2.40%  (p=0.016 n=5+4)
        quote[\u03b1]        1.21ms ± 0%  1.12ms ± 0%   -7.47%  (p=0.008 n=5+5)
        quote[\u65e5]         785µs ± 0%   738µs ± 2%   -5.97%  (p=0.016 n=5+4)
        quote[\U0001f64f]    1.04ms ± 0%  0.92ms ± 1%  -11.73%  (p=0.008 n=5+5)
        stdquote             1.18µs ± 0%  1.19µs ± 0%   +0.54%  (p=0.008 n=5+5)
        unquote[a]           1.26ms ± 0%  1.08ms ± 0%  -14.66%  (p=0.008 n=5+5)
        unquote[\u03b1]       911µs ± 1%   797µs ± 0%  -12.55%  (p=0.008 n=5+5)
        unquote[\u65e5]       592µs ± 0%   522µs ± 0%  -11.81%  (p=0.008 n=5+5)
        unquote[\U0001f64f]  3.46ms ± 0%  3.21ms ± 0%   -7.34%  (p=0.008 n=5+5)
        stdunquote            812ns ± 1%   815ns ± 0%     ~     (p=0.183 n=5+5)
    533bd30a
_strconv.pyx 5.38 KB