Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-91432: Add more FOR_ITER specializations #94096

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ _PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
*size_ptr = size;
}

typedef struct {
PyObject_HEAD
PyDictObject *di_dict; /* Set to NULL when iterator is exhausted */
Py_ssize_t di_used;
Py_ssize_t di_pos;
PyObject* di_result; /* reusable result tuple for iteritems */
Py_ssize_t len;
} _PyDictIterObject;

int _PyDictItemsIter_GetNext(_PyDictIterObject *, PyObject **);

#ifdef __cplusplus
}
#endif
Expand Down
26 changes: 26 additions & 0 deletions Include/internal/pycore_enumerate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef Py_INTERNAL_ENUMERATE_H
#define Py_INTERNAL_ENUMERATE_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif

typedef struct {
PyObject_HEAD
Py_ssize_t en_index; /* current index of enumeration */
PyObject* en_sit; /* secondary iterator of enumeration */
PyObject* en_result; /* result tuple */
PyObject* en_longindex; /* index for sequences >= PY_SSIZE_T_MAX */
PyObject* one; /* borrowed reference */
} _PyEnumObject;

int
_PyEnum_GetNext(_PyEnumObject *en, PyObject **stack, PyObject **index_target);

#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_ENUMERATE_H */
57 changes: 30 additions & 27 deletions Include/internal/pycore_opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Include/internal/pycore_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ struct _Py_tuple_state {
extern PyObject *_PyTuple_FromArray(PyObject *const *, Py_ssize_t);
extern PyObject *_PyTuple_FromArraySteal(PyObject *const *, Py_ssize_t);

typedef struct {
PyObject_HEAD
Py_ssize_t it_index;
PyTupleObject *it_seq; /* Set to NULL when iterator is exhausted */
} _PyTupleIterObject;

#ifdef __cplusplus
}
#endif
Expand Down
67 changes: 35 additions & 32 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ def jabs_op(name, op):
"FOR_ITER_ADAPTIVE",
"FOR_ITER_LIST",
"FOR_ITER_RANGE",
"FOR_ITER_TUPLE",
"FOR_ITER_DICT_ITEMS",
"FOR_ITER_ENUMERATE",
],
"JUMP_BACKWARD": [
"JUMP_BACKWARD_QUICK",
Expand Down
1 change: 1 addition & 0 deletions Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ PYTHON_HEADERS= \
$(srcdir)/Include/internal/pycore_dict.h \
$(srcdir)/Include/internal/pycore_descrobject.h \
$(srcdir)/Include/internal/pycore_dtoa.h \
$(srcdir)/Include/internal/pycore_enumerate.h \
$(srcdir)/Include/internal/pycore_exceptions.h \
$(srcdir)/Include/internal/pycore_fileutils.h \
$(srcdir)/Include/internal/pycore_floatobject.h \
Expand Down
Loading