bpo-31659: ssl: Don't use textwrap.fill() to format PEM cert by methane · Pull Request #3849 · python/cpython (original) (raw)

I'm sorry about variable name. I didn't care about name for very short scope variables.

In case of performance, as serhiy said, cert size won't be arbitrary large.
And old code used temporal string for body part. This commit didn't make anythong worse.

$ ./python -m perf timeit -s "import textwrap; s='a'*1000" -- 'textwrap.fill(s, 60)'
.....................
Mean +- std dev: 192 us +- 10 us

$ ./python -m perf timeit -s "import textwrap; s='a'*1000" -- 'x=[]; x+=[s[i:i+60] for i in range(0,len(s),60)]; "\n".join(x)'
.....................
Mean +- std dev: 4.66 us +- 0.06 us