Message258276
I implemented overkill optimization in _PyUnicodeWriter API used by str.format() and str%args. If the result is the input, the string is not copied by value, but by reference.
>>> x="hello"
>>> ("%s" % x) is x
True
>>> ("{}".format(x)) is x
True
If the format string adds something before/after, the string is duplicated:
>>> ("x=%s" % x) is x
False
>>> ("x={}".format(x)) is x
False
The optimization is implemented in _PyUnicodeWriter_WriteStr():
https://hg.python.org/cpython/file/32a4e7b337c9/Objects/unicodeobject.c#l13604 |
|
Date |
User |
Action |
Args |
2016-01-15 08:15:26 | vstinner | set | recipients:
+ vstinner, eric.smith, steven.daprano, poostenr, ubehera |
2016-01-15 08:15:26 | vstinner | set | messageid: <1452845726.72.0.186564910152.issue26118@psf.upfronthosting.co.za> |
2016-01-15 08:15:26 | vstinner | link | issue26118 messages |
2016-01-15 08:15:26 | vstinner | create | |
|