[Python-Dev] Q: why doesn't list.extend use the sequence interface?
Fredrik Lundh
Fredrik Lundh" <effbot@telia.com
Sat, 17 Jun 2000 10:40:20 +0200
mark wrote:
> > so in other words, this construct is more than 4 times faster
> > than plain use of PySequence_GetItem.
>=20
> Good stuff!
>=20
> > guess it's time to fix a couple of things in PIL...
>=20
> Its a fair bit of code to duplicate everywhere you want the speed =
increase.
> How can we add a similar scheme to the core, so the changes people =
need to
> make are trivial (to the point where the change is zero!)?
the first part is trivial; just add something like this to
Objects/abstract.c:
PyObject*
PySequence_TupleOrList(PyObject* seq)
{
if (PyList_Check(seq) || PyTuple_Check(seq))
Py_INCREF(seq);
else if (PySequence_Check(seq))
seq =3D PySequence_Tuple(seq);
else {
PyErr_SetString(PyExc_TypeError, "argument must be a sequence");
seq =3D NULL;
}
return seq;
}
the second parts is harder -- and that's of course where the
real performance boost comes from. as far as I'm aware, very
few C compilers can "specialize" loops for you...
</F>