summaryrefslogtreecommitdiffstats
path: root/Python/bytecodes.c
diff options
context:
space:
mode:
authorKen Jin <kenjin@python.org>2022-12-09 10:27:01 (GMT)
committerGitHub <noreply@github.com>2022-12-09 10:27:01 (GMT)
commit748c6c0921ee02a19e01a35f03ce5f4d9cfde5a6 (patch)
treedf269e2c07729851f0f02e77713c140c0db15064 /Python/bytecodes.c
parent0448deac70be94792616c0fb0c9cb524de9a09b8 (diff)
downloadcpython-748c6c0921ee02a19e01a35f03ce5f4d9cfde5a6.zip
cpython-748c6c0921ee02a19e01a35f03ce5f4d9cfde5a6.tar.gz
cpython-748c6c0921ee02a19e01a35f03ce5f4d9cfde5a6.tar.bz2
GH-100110: Specialize FOR_ITER for tuples (GH-100109)
* Specialize FOR_ITER for tuples
Diffstat (limited to 'Python/bytecodes.c')
-rw-r--r--Python/bytecodes.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 7a1bfdc..5807bd5 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2524,6 +2524,29 @@ dummy_func(
}
// stack effect: ( -- __0)
+ inst(FOR_ITER_TUPLE) {
+ assert(cframe.use_tracing == 0);
+ _PyTupleIterObject *it = (_PyTupleIterObject *)TOP();
+ DEOPT_IF(Py_TYPE(it) != &PyTupleIter_Type, FOR_ITER);
+ STAT_INC(FOR_ITER, hit);
+ PyTupleObject *seq = it->it_seq;
+ if (seq) {
+ if (it->it_index < PyTuple_GET_SIZE(seq)) {
+ PyObject *next = PyTuple_GET_ITEM(seq, it->it_index++);
+ PUSH(Py_NewRef(next));
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER);
+ goto end_for_iter_tuple; // End of this instruction
+ }
+ it->it_seq = NULL;
+ Py_DECREF(seq);
+ }
+ STACK_SHRINK(1);
+ Py_DECREF(it);
+ JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + oparg + 1);
+ end_for_iter_tuple:
+ }
+
+ // stack effect: ( -- __0)
inst(FOR_ITER_RANGE) {
assert(cframe.use_tracing == 0);
_PyRangeIterObject *r = (_PyRangeIterObject *)TOP();