mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-41361: Optimized argument parsing for deque_rotate (GH-24796)
This commit is contained in:
parent
d69ae758a0
commit
448801da96
2 changed files with 13 additions and 1 deletions
|
|
@ -880,9 +880,20 @@ deque_rotate(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
|
|||
{
|
||||
Py_ssize_t n=1;
|
||||
|
||||
if (!_PyArg_ParseStack(args, nargs, "|n:rotate", &n)) {
|
||||
if (!_PyArg_CheckPositional("deque.rotate", nargs, 0, 1)) {
|
||||
return NULL;
|
||||
}
|
||||
if (nargs) {
|
||||
PyObject *index = _PyNumber_Index(args[0]);
|
||||
if (index == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
n = PyLong_AsSsize_t(index);
|
||||
Py_DECREF(index);
|
||||
if (n == -1 && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_deque_rotate(deque, n))
|
||||
Py_RETURN_NONE;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue