Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-91432: Specialize FOR_ITER#91713
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
3a7f8df3b5ce1eb21b5f437269cfea0a7ee0751228dc80fdae4294101cb2de773fa01c4213582bf58358bd7575edb8754b2050c4e824e9666b16772c2a75a56696384d29709122635a6f360d6581e0500c2eab6825689c3b5df0472b1c17091d280ceba5e605b153d776f9a740565a689ba5b796cdf0e403dde6af1e2d39463c3b9ed29777188b35736d0999ad2e969d55868f2d6ee26db21da1File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -770,7 +770,7 @@ rangeiter_next(_PyRangeIterObject *r) | ||
| /* cast to unsigned to avoid possible signed overflow | ||
| in intermediate calculations. */ | ||
| return PyLong_FromLong((long)(r->start + | ||
| (digit)(r->index++) * r->step)); | ||
| return NULL; | ||
| } | ||
| @@ -911,9 +911,9 @@ fast_range_iter(long start, long stop, long step, long len) | ||
| _PyRangeIterObject *it = PyObject_New(_PyRangeIterObject, &PyRangeIter_Type); | ||
| if (it == NULL) | ||
| return NULL; | ||
| it->start =Py_SAFE_DOWNCAST(start, long, sdigit); | ||
| ||
| it->step =Py_SAFE_DOWNCAST(step, long, sdigit); | ||
| it->len =Py_SAFE_DOWNCAST(len, long, sdigit); | ||
| it->index = 0; | ||
| return (PyObject *)it; | ||
| } | ||
| @@ -1097,20 +1097,13 @@ range_iter(PyObject *seq) | ||
| goto long_range; | ||
| } | ||
| ulen = get_len_of_range(lstart, lstop, lstep); | ||
| if (ulen > PyLong_MASK || | ||
| lstart > PyLong_MASK || lstart < -(long)PyLong_MASK || | ||
| lstop > PyLong_MASK || lstop < -(long)PyLong_MASK || | ||
| lstep > PyLong_MASK || lstep < -(long)PyLong_MASK) | ||
| { | ||
| goto long_range; | ||
| } | ||
| return fast_range_iter(lstart, lstop, lstep, (long)ulen); | ||
| long_range: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4399,17 +4399,42 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int | ||
| _PyRangeIterObject *r = (_PyRangeIterObject *)TOP(); | ||
| DEOPT_IF(Py_TYPE(r) != &PyRangeIter_Type, FOR_ITER); | ||
| STAT_INC(FOR_ITER, hit); | ||
| _Py_CODEUNIT next = next_instr[INLINE_CACHE_ENTRIES_FOR_ITER]; | ||
| assert(_PyOpcode_Deopt[_Py_OPCODE(next)] == STORE_FAST); | ||
| PyObject **local_ptr = &GETLOCAL(_Py_OPARG(next)); | ||
| PyObject *local = *local_ptr; | ||
| if (r->index >= r->len) { | ||
| goto iterator_exhausted_no_error; | ||
| } | ||
| JUMPBY(INLINE_CACHE_ENTRIES_FOR_ITER + 1); | ||
| sdigit value = r->start + (digit)(r->index++) * r->step; | ||
| if (value < _PY_NSMALLPOSINTS && value >= -_PY_NSMALLNEGINTS) { | ||
| ||
| *local_ptr = Py_NewRef(&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS+value]); | ||
| Py_XDECREF(local); | ||
| NOTRACE_DISPATCH(); | ||
| } | ||
sweeneyde marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| if (local && PyLong_CheckExact(local) && Py_REFCNT(local) == 1) { | ||
| if (value > 0) { | ||
| assert(value <= PyLong_MASK); | ||
| ((PyLongObject *)local)->ob_digit[0] = value; | ||
| Py_SET_SIZE(local, 1); | ||
| } | ||
| else { | ||
| assert(value >= -(sdigit)PyLong_MASK); | ||
| ((PyLongObject *)local)->ob_digit[0] = -(sdigit)value; | ||
| Py_SET_SIZE(local, -1); | ||
| } | ||
| NOTRACE_DISPATCH(); | ||
| } | ||
| PyObject *res = PyLong_FromLong(value); | ||
| if (res == NULL) { | ||
| // undo the JUMPBY | ||
| next_instr -= INLINE_CACHE_ENTRIES_FOR_ITER + 1; | ||
| goto error; | ||
| } | ||
| *local_ptr = res; | ||
| Py_XDECREF(local); | ||
| NOTRACE_DISPATCH(); | ||
| } | ||
| TARGET(BEFORE_ASYNC_WITH) { | ||