\begin{itemize}
+\item The inner loops for \class{list} and \class{tuple} slicing
+ were optimized and now run about one-third faster.
+
\item The machinery for growing and shrinking lists was optimized
for speed and for space efficiency. Small lists (under eight elements)
never over-allocate by more than three elements. Large lists do not
list_slice(PyListObject *a, int ilow, int ihigh)
{
PyListObject *np;
+ PyObject **src, **dest;
int i, len;
if (ilow < 0)
ilow = 0;
if (np == NULL)
return NULL;
+ src = a->ob_item + ilow;
+ dest = np->ob_item;
for (i = 0; i < len; i++) {
- PyObject *v = a->ob_item[i+ilow];
+ PyObject *v = src[i];
Py_INCREF(v);
- np->ob_item[i] = v;
+ dest[i] = v;
}
return (PyObject *)np;
}
register int selflen = PyList_GET_SIZE(self);
int blen;
register int i;
+ PyObject **src, **dest;
if (PyObject_Size(b) == 0) {
/* short circuit when b is empty */
}
/* populate the end of self with b's items */
- if (PyList_Check(b)) {
- for (i = 0; i < blen; i++) {
- PyObject *o = PyList_GET_ITEM(b, i);
- Py_INCREF(o);
- PyList_SET_ITEM(self, i+selflen, o);
- }
- } else {
+ if (PyList_Check(b))
+ src = ((PyListObject *)b)->ob_item;
+ else {
assert (PyTuple_Check(b));
- for (i = 0; i < blen; i++) {
- PyObject *o = PyTuple_GET_ITEM(b, i);
- Py_INCREF(o);
- PyList_SET_ITEM(self, i+selflen, o);
- }
+ src = ((PyTupleObject *)b)->ob_item;
+ }
+ dest = self->ob_item + selflen;
+ for (i = 0; i < blen; i++) {
+ PyObject *o = src[i];
+ Py_INCREF(o);
+ dest[i] = o;
}
Py_DECREF(b);
return 0;
tupleslice(register PyTupleObject *a, register int ilow, register int ihigh)
{
register PyTupleObject *np;
+ PyObject **src, **dest;
register int i;
+ int len;
if (ilow < 0)
ilow = 0;
if (ihigh > a->ob_size)
Py_INCREF(a);
return (PyObject *)a;
}
- np = (PyTupleObject *)PyTuple_New(ihigh - ilow);
+ len = ihigh - ilow;
+ np = (PyTupleObject *)PyTuple_New(len);
if (np == NULL)
return NULL;
- for (i = ilow; i < ihigh; i++) {
- PyObject *v = a->ob_item[i];
+ src = a->ob_item + ilow;
+ dest = np->ob_item;
+ for (i = 0; i < len; i++) {
+ PyObject *v = src[i];
Py_INCREF(v);
- np->ob_item[i - ilow] = v;
+ dest[i] = v;
}
return (PyObject *)np;
}