Adding tuple as builtin type
Claudio Freire <[email protected]> Wed, 11 Feb 2009 12:37:14 -0200
| Newsgroups | gmane.comp.python.pyrex |
|---|---|
| Message-ID | <[email protected]> |
Is there a reason why tuple hasn't been added as a builtin type, as list was? In my code, there is heavy usage of tuples, and the generic code generated by pyrex when working with them as generic "object"s leaves something to be desired. In particular, I rely heavily on returning tuples and then unpacking them as a way to return more than one value: cdef tuple threevalues(): return (1,2,3) def dosomething(): cdef int a,b,c a,b,c = threevalues() return a+b+c Without pyrex knowing of that return value's tuple status, the generated code for unpacking is rather cumbersome, using iterators and lots of checking. Knowing it's a tuple, only a few calls to PyTuple_xxx API would be involved in unpacking those values. Since I use pyrex code to implement compute-intensive parts of my application, in performance-critical sections, the speed improvement would be highly appreciated. I considered using lists, but lists break things someplace else in the app (I need it to be of an immutable type). Sorry if it came up already, I searched through the archives a bit and didn't see anything about the subject.