cython/cython — pull request #98 by scoder (2012-03-20 17:27:34+00:00)
Title: optimised tuple/list/iterable unpacking

For long item sequences, the currently generated unrolled loops tend to be exceedingly long, complex and also surprisingly slow in cases, both for the C compiler and at runtime.

This change replaces the implementation by a loop if the number of items is larger than 3. This appears to be substantially faster for lists and produces much shorter C code. For tuples, the original implementation is kept because unrolling the loop seems to be faster here and the assembly output is really simple and fast.

Also note that this change disables the optimisation for other Pythons than CPython (e.g. PyPy) and uses normal iteration unpacking there. Specifically, PyPy does not have a good way of dealing with borrowed references, which PyTuple_GET_ITEM() returns, so unpacking with an iterator is much safer here.