[Cython] enumerate optimisation in cython-unstable

Stefan Behnel stefan_ml at behnel.de
Fri May 15 22:52:50 CEST 2009


Hi,

couldn't resist to announce that this little optimisation is now in
cython-unstable. An example of a corresponding for-in loop is below.

Have fun,

Stefan

/* ...
 * def multi_c_enumerate():
 *     cdef int a,b,c,d
 *     for a,(b,(c,d)) in enumerate(enumerate(enumerate(range(1,5)))):
        # <<<<<<<<<<<<<<
 *         print a,b,c,d
 */
  __pyx_t_1 = 0;
  __pyx_t_2 = 0;
  __pyx_t_3 = 0;
  for (__pyx_t_4 = 1; __pyx_t_4 < 5; __pyx_t_4+=1) {
    __pyx_v_d = __pyx_t_4;
    __pyx_v_c = __pyx_t_3;
    __pyx_t_3 = (__pyx_t_3 + 1);
    __pyx_v_b = __pyx_t_2;
    __pyx_t_2 = (__pyx_t_2 + 1);
    __pyx_v_a = __pyx_t_1;
    __pyx_t_1 = (__pyx_t_1 + 1);



More information about the Cython-dev mailing list