[Python-checkins] python/dist/src/Objects listobject.c,2.200,2.201
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Mon Apr 12 09:05:12 EDT 2004
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16419
Modified Files:
listobject.c
Log Message:
* Specialize ins1() into app1() for appends. Saves several unnecessary
steps and further improves the speed of list append.
* Add guards to the list iterator length method to handle corner cases.
Index: listobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/listobject.c,v
retrieving revision 2.200
retrieving revision 2.201
diff -C2 -d -r2.200 -r2.201
*** listobject.c 20 Mar 2004 22:19:23 -0000 2.200
--- listobject.c 12 Apr 2004 13:05:09 -0000 2.201
***************
*** 181,184 ****
--- 181,204 ----
}
+ static int
+ app1(PyListObject *self, PyObject *v)
+ {
+ int n = PyList_GET_SIZE(self);
+
+ assert (v != NULL);
+ if (n == INT_MAX) {
+ PyErr_SetString(PyExc_OverflowError,
+ "cannot add more objects to list");
+ return -1;
+ }
+
+ if (list_resize(self, n+1) == -1)
+ return -1;
+
+ Py_INCREF(v);
+ PyList_SET_ITEM(self, n, v);
+ return 0;
+ }
+
int
PyList_Append(PyObject *op, PyObject *newitem)
***************
*** 188,193 ****
return -1;
}
! return ins1((PyListObject *)op,
! (int) ((PyListObject *)op)->ob_size, newitem);
}
--- 208,216 ----
return -1;
}
! if (newitem == NULL) {
! PyErr_BadInternalCall();
! return -1;
! }
! return app1((PyListObject *)op, newitem);
}
***************
*** 727,731 ****
PyList_SET_ITEM(self, i, item); /* steals ref */
else {
! int status = ins1(self, self->ob_size, item);
Py_DECREF(item); /* append creates a new ref */
if (status < 0)
--- 750,754 ----
PyList_SET_ITEM(self, i, item); /* steals ref */
else {
! int status = app1(self, item);
Py_DECREF(item); /* append creates a new ref */
if (status < 0)
***************
*** 2685,2690 ****
listiter_len(listiterobject *it)
{
! if (it->it_seq)
! return PyList_GET_SIZE(it->it_seq) - it->it_index;
return 0;
}
--- 2708,2717 ----
listiter_len(listiterobject *it)
{
! int len;
! if (it->it_seq) {
! len = PyList_GET_SIZE(it->it_seq) - it->it_index;
! if (len >= 0)
! return len;
! }
return 0;
}
***************
*** 2800,2804 ****
listreviter_len(listreviterobject *it)
{
! return it->it_index + 1;
}
--- 2827,2834 ----
listreviter_len(listreviterobject *it)
{
! int len = it->it_index + 1;
! if (it->it_seq == NULL || PyList_GET_SIZE(it->it_seq) < len)
! return 0;
! return len;
}
More information about the Python-checkins
mailing list