mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Refactor and optimize code for UNPACK_SEQUENCE.
* Defer error handling for wrong number of arguments to the unpack_iterable() function. Cuts the code size almost in half. * Replace function calls to PyList_Size() and PyTuple_Size() with their smaller and faster macro counterparts. * Move the constant structure references outside of the inner loops.
This commit is contained in:
parent
4b6b7f1515
commit
f114a3ae63
1 changed files with 13 additions and 27 deletions
|
@ -1721,35 +1721,21 @@ eval_frame(PyFrameObject *f)
|
||||||
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
|
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
|
||||||
case UNPACK_SEQUENCE:
|
case UNPACK_SEQUENCE:
|
||||||
v = POP();
|
v = POP();
|
||||||
if (PyTuple_CheckExact(v)) {
|
if (PyTuple_CheckExact(v) && PyTuple_GET_SIZE(v) == oparg) {
|
||||||
if (PyTuple_Size(v) != oparg) {
|
PyObject **items = ((PyTupleObject *)v)->ob_item;
|
||||||
PyErr_SetString(PyExc_ValueError,
|
while (oparg--) {
|
||||||
"unpack tuple of wrong size");
|
w = items[oparg];
|
||||||
why = WHY_EXCEPTION;
|
Py_INCREF(w);
|
||||||
|
PUSH(w);
|
||||||
}
|
}
|
||||||
else {
|
} else if (PyList_CheckExact(v) && PyList_GET_SIZE(v) == oparg) {
|
||||||
for (; --oparg >= 0; ) {
|
PyObject **items = ((PyListObject *)v)->ob_item;
|
||||||
w = PyTuple_GET_ITEM(v, oparg);
|
while (oparg--) {
|
||||||
Py_INCREF(w);
|
w = items[oparg];
|
||||||
PUSH(w);
|
Py_INCREF(w);
|
||||||
}
|
PUSH(w);
|
||||||
}
|
}
|
||||||
}
|
} else if (unpack_iterable(v, oparg,
|
||||||
else if (PyList_CheckExact(v)) {
|
|
||||||
if (PyList_Size(v) != oparg) {
|
|
||||||
PyErr_SetString(PyExc_ValueError,
|
|
||||||
"unpack list of wrong size");
|
|
||||||
why = WHY_EXCEPTION;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (; --oparg >= 0; ) {
|
|
||||||
w = PyList_GET_ITEM(v, oparg);
|
|
||||||
Py_INCREF(w);
|
|
||||||
PUSH(w);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (unpack_iterable(v, oparg,
|
|
||||||
stack_pointer + oparg))
|
stack_pointer + oparg))
|
||||||
stack_pointer += oparg;
|
stack_pointer += oparg;
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue