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 serhiy.storchaka, vstinner, xiang.zhang
Date 2016-11-18.15:43:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479483801.48.0.659970023373.issue28398@psf.upfronthosting.co.za>
In-reply-to
Content
To reduce the memory footprint, it's important that we reuse internal Unicode singletons. For the empty string singleton, you have two choices:

* if length is equal to zero, return the singleton
* create a string and then call unicode_result()

unicode_result() should be used when the output length is not easy to compute or when the code is complex.

Here is the code is very simple and the output length is obvious.

Serhiy: "In what circumstances _PyUnicode_FromASCII is called with size=0?"

I checked the current code: I'm unable to see any function which can call _PyUnicode_FromASCII() with size=0.


Xiang: "IMHO, _PyUnicode_FromASCII is a private API and could be used in other places in future. We should not rely on the caller to check and return the singleton empty string."

I agree. Xiang's patch is short and makes sense, so I vote +1 on it.

I let Serhiy decides if the patch should be merged or not.

If we decide to reject the patch, I suggest to add the following code at the beginning of _PyUnicode_FromASCII:

/* Detect missed optimization */
assert(size != 0);
History
Date User Action Args
2016-11-18 15:43:21vstinnersetrecipients: + vstinner, serhiy.storchaka, xiang.zhang
2016-11-18 15:43:21vstinnersetmessageid: <1479483801.48.0.659970023373.issue28398@psf.upfronthosting.co.za>
2016-11-18 15:43:21vstinnerlinkissue28398 messages
2016-11-18 15:43:20vstinnercreate