bpo-40521: Optimize PyBytes_FromStringAndSize(str, 0) (GH-21142)

Always create the empty bytes string singleton.

Optimize PyBytes_FromStringAndSize(str, 0): it no longer has to check
if the empty string singleton was created or not, it is always
available.

Add functions:

* _PyBytes_Init()
* bytes_get_empty(), bytes_new_empty()
* bytes_create_empty_string_singleton()
* unicode_create_empty_string_singleton()

_Py_unicode_state: rename empty structure member to empty_string.
This commit is contained in:
Victor Stinner 2020-06-25 14:07:40 +02:00 committed by GitHub
parent 0f8ec1fff0
commit 91698d8caa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 53 deletions

View file

@ -607,6 +607,11 @@ pycore_init_types(PyThreadState *tstate)
return status;
}
status = _PyBytes_Init(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
status = _PyExc_Init(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;