Cython already optimises the common idiom for ... in [x, y, z]
into the slightly more efficient for ... in (x, y, z)
, and then uses direct tuple array indexing for the iteration.
This could be optimised even further by using a stack allocated C array instead of the Python tuple. That would also allow iteration over plain C values for uniform tuple types and could avoid any intermediate Python object creation. In order to support that, it is necessary to 1) replace the TupleNode
by a new CArrayNode
(or at least mark it as special) early in the IterationTransform
, 2) apply the C array transformation to the for-loop (also in IterationTransform
), and then 3) determine the actual array type in the analyse_types()
method (probably object
in most cases).
I would start by writing cases in a new test file tests/run/for_in_tuple.pyx
, similar to for_in_range.pyx
, looking at the generated code (try the debug_trace_code_generation
option in DebugFlags.py
), and then going through the classes listed above and start playing with them.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4