[Python-checkins] python/dist/src/Objects listobject.c,2.196,2.197
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Sun Mar 14 01:42:26 EST 2004
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24604/Objects
Modified Files:
listobject.c
Log Message:
list_resize() now has an "exact" option for bypassing the overallocation
scheme in situations that likely won't benefit from it. This further
improves memory utilization from Py2.3 which always over-allocates
except for PyList_New().
Situations expected to benefit from over-allocation:
list.insert(), list.pop(), list.append(), and list.extend()
Situations deemed unlikely to benefit:
list_inplace_repeat, list_ass_slice, list_ass_subscript
The most gray area was for listextend_internal() which only runs
when the argument is a list or a tuple. This could be viewed as
a one-time fixed length addition or it could be viewed as wrapping
a series of appends. I left its over-allocation turned on but
could be convinced otherwise.
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.196
retrieving revision 2.197
diff -C2 -d -r2.196 -r2.197
*** listobject.c 12 Mar 2004 16:38:17 -0000 2.196
--- listobject.c 14 Mar 2004 06:42:23 -0000 2.197
***************
*** 10,14 ****
static int
! list_resize(PyListObject *self, int newsize)
{
PyObject **items;
--- 10,14 ----
static int
! list_resize(PyListObject *self, int newsize, int exact)
{
PyObject **items;
***************
*** 34,38 ****
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
*/
! _new_size = (newsize >> 3) + (self->ob_size < 8 ? 3 : 6) + newsize;
items = self->ob_item;
if (_new_size <= ((~(size_t)0) / sizeof(PyObject *)))
--- 34,41 ----
* The growth pattern is: 0, 4, 8, 16, 25, 35, 46, 58, 72, 88, ...
*/
! if (exact)
! _new_size = newsize;
! else
! _new_size = (newsize>>3) + (self->ob_size < 8 ? 3 : 6) + newsize;
items = self->ob_item;
if (_new_size <= ((~(size_t)0) / sizeof(PyObject *)))
***************
*** 153,157 ****
}
! if (list_resize(self, n+1) == -1)
return -1;
--- 156,160 ----
}
! if (list_resize(self, n+1, 0) == -1)
return -1;
***************
*** 519,523 ****
memmove(&item[ihigh+d], &item[ihigh],
(a->ob_size - ihigh)*sizeof(PyObject *));
! list_resize(a, a->ob_size + d);
item = a->ob_item;
}
--- 522,526 ----
memmove(&item[ihigh+d], &item[ihigh],
(a->ob_size - ihigh)*sizeof(PyObject *));
! list_resize(a, a->ob_size + d, 1);
item = a->ob_item;
}
***************
*** 525,529 ****
else { /* Insert d items; recycle ihigh-ilow items */
s = a->ob_size;
! if (list_resize(a, s+d) == -1) {
if (recycle != NULL)
PyMem_DEL(recycle);
--- 528,532 ----
else { /* Insert d items; recycle ihigh-ilow items */
s = a->ob_size;
! if (list_resize(a, s+d, 1) == -1) {
if (recycle != NULL)
PyMem_DEL(recycle);
***************
*** 589,593 ****
}
! if (list_resize(self, size*n) == -1)
return NULL;
--- 592,596 ----
}
! if (list_resize(self, size*n, 1) == -1)
return NULL;
***************
*** 681,685 ****
}
! if (list_resize(self, selflen + blen) == -1) {
Py_DECREF(b);
return -1;
--- 684,688 ----
}
! if (list_resize(self, selflen + blen, 0) == -1) {
Py_DECREF(b);
return -1;
***************
*** 734,738 ****
m = self->ob_size;
mn = m + n;
! if (list_resize(self, mn) == -1)
goto error;
memset(&(self->ob_item[m]), 0, sizeof(*self->ob_item) * n);
--- 737,741 ----
m = self->ob_size;
mn = m + n;
! if (list_resize(self, mn, 0) == -1)
goto error;
memset(&(self->ob_item[m]), 0, sizeof(*self->ob_item) * n);
***************
*** 819,823 ****
v = self->ob_item[i];
if (i == self->ob_size - 1) {
! if (list_resize(self, self->ob_size - 1) == -1)
return NULL;
return v;
--- 822,826 ----
v = self->ob_item[i];
if (i == self->ob_size - 1) {
! if (list_resize(self, self->ob_size - 1, 0) == -1)
return NULL;
return v;
***************
*** 2518,2522 ****
self->ob_size -= slicelength;
! list_resize(self, self->ob_size);
for (i = 0; i < slicelength; i++) {
--- 2521,2525 ----
self->ob_size -= slicelength;
! list_resize(self, self->ob_size, 1);
for (i = 0; i < slicelength; i++) {
More information about the Python-checkins
mailing list