bpo-36030: Add _PyTuple_FromArray() function by sir-sigurd · Pull Request #11954 · python/cpython
@serhiy-storchaka, @methane, @rhettinger: Would you mind to review this change? IMHO the change is good, but without "tuple_from_array(PyObject *const *src, Py_ssize_t n, Py_ssize_t step)": without the step argument.
I asked @sir-sigurd to revert his optimization to not initialize items to NULL: he reverted it to make the PR simpler. He will propose a separated PR for this micro-optimization, once this one is merged.
IMHO this change is good because the API _PyTuple_FromArray() is easy to use, it removes a lot of code, and may open the way to further optimization later (that should be discussed later). Ah, and the new function is private ("internal"), so it can be reverted anytime if needed.
So the last thing is to remove the step argument. IMHO it's not worth it, it was used once in tuplesubscript. Keeping the existing tuplesubscript() code is better to avoid to make _PyTuple_FromArray() more complex and maybe slower (it's hard to check if the machine code is the most efficient on all architectures). But I expected than hardcoded step=1 helps the compiler and the CPU to run faster.