[Python-checkins] cpython: Optimize PyBytes_FromObject(): only overallocate when size=0 to not get the
victor.stinner
python-checkins at python.org
Sun Aug 17 21:15:29 CEST 2014
http://hg.python.org/cpython/rev/452f9486a011
changeset: 92141:452f9486a011
user: Victor Stinner <victor.stinner at gmail.com>
date: Sun Aug 17 21:12:18 2014 +0200
summary:
Optimize PyBytes_FromObject(): only overallocate when size=0 to not get the
empty string singleton
files:
Objects/bytesobject.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3174,10 +3174,12 @@
returning a shared empty bytes string. This required because we
want to call _PyBytes_Resize() the returned object, which we can
only do on bytes objects with refcount == 1. */
- size += 1;
+ if (size == 0)
+ size = 1;
new = PyBytes_FromStringAndSize(NULL, size);
if (new == NULL)
return NULL;
+ assert(Py_REFCNT(new) == 1);
/* Get the iterator */
it = PyObject_GetIter(x);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list