Kaydet (Commit) 88d146b7 authored tarafından Victor Stinner's avatar Victor Stinner

Optimize PyBytes_FromObject(): only overallocate when size=0 to not get the

empty string singleton
üst cfcde8ca
...@@ -3174,10 +3174,12 @@ PyBytes_FromObject(PyObject *x) ...@@ -3174,10 +3174,12 @@ PyBytes_FromObject(PyObject *x)
returning a shared empty bytes string. This required because we returning a shared empty bytes string. This required because we
want to call _PyBytes_Resize() the returned object, which we can want to call _PyBytes_Resize() the returned object, which we can
only do on bytes objects with refcount == 1. */ only do on bytes objects with refcount == 1. */
size += 1; if (size == 0)
size = 1;
new = PyBytes_FromStringAndSize(NULL, size); new = PyBytes_FromStringAndSize(NULL, size);
if (new == NULL) if (new == NULL)
return NULL; return NULL;
assert(Py_REFCNT(new) == 1);
/* Get the iterator */ /* Get the iterator */
it = PyObject_GetIter(x); it = PyObject_GetIter(x);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment