This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients eric.smith, poostenr, steven.daprano, ubehera, vstinner
Date 2016-01-15.08:15:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452845726.72.0.186564910152.issue26118@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-01-15 08:15:26vstinnersetrecipients: + vstinner, eric.smith, steven.daprano, poostenr, ubehera
2016-01-15 08:15:26vstinnersetmessageid: <1452845726.72.0.186564910152.issue26118@psf.upfronthosting.co.za>
2016-01-15 08:15:26vstinnerlinkissue26118 messages
2016-01-15 08:15:26vstinnercreate