mirror of https://github.com/python/cpython
Small code improvements for readability, code size, and/or speed.
BINARY_SUBSCR: * invert test for normal case fall through * eliminate err handling code by jumping to slow_case LOAD_LOCALS: * invert test for normal case fall through * continue instead of break for the non-error case STORE_NAME and DELETE_NAME: * invert test for normal case fall through LOAD_NAME: * continue instead of break for the non-error case DELETE_FAST: * invert test for normal case fall through LOAD_DEREF: * invert test for normal case fall through * continue instead of break for the non-error case
This commit is contained in:
parent
22ab06e4de
commit
467a698bd2
|
@ -1155,18 +1155,15 @@ eval_frame(PyFrameObject *f)
|
||||||
long i = PyInt_AsLong(w);
|
long i = PyInt_AsLong(w);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
i += PyList_GET_SIZE(v);
|
i += PyList_GET_SIZE(v);
|
||||||
if (i < 0 ||
|
if (i >= 0 && i < PyList_GET_SIZE(v)) {
|
||||||
i >= PyList_GET_SIZE(v)) {
|
|
||||||
PyErr_SetString(PyExc_IndexError,
|
|
||||||
"list index out of range");
|
|
||||||
x = NULL;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
x = PyList_GET_ITEM(v, i);
|
x = PyList_GET_ITEM(v, i);
|
||||||
Py_INCREF(x);
|
Py_INCREF(x);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
goto slow_get;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
slow_get:
|
||||||
x = PyObject_GetItem(v, w);
|
x = PyObject_GetItem(v, w);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_DECREF(w);
|
Py_DECREF(w);
|
||||||
|
@ -1608,13 +1605,12 @@ eval_frame(PyFrameObject *f)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOAD_LOCALS:
|
case LOAD_LOCALS:
|
||||||
if ((x = f->f_locals) == NULL) {
|
if ((x = f->f_locals) != NULL) {
|
||||||
PyErr_SetString(PyExc_SystemError,
|
|
||||||
"no locals");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Py_INCREF(x);
|
Py_INCREF(x);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PyErr_SetString(PyExc_SystemError, "no locals");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RETURN_VALUE:
|
case RETURN_VALUE:
|
||||||
|
@ -1687,28 +1683,28 @@ eval_frame(PyFrameObject *f)
|
||||||
case STORE_NAME:
|
case STORE_NAME:
|
||||||
w = GETITEM(names, oparg);
|
w = GETITEM(names, oparg);
|
||||||
v = POP();
|
v = POP();
|
||||||
if ((x = f->f_locals) == NULL) {
|
if ((x = f->f_locals) != NULL) {
|
||||||
|
err = PyDict_SetItem(x, w, v);
|
||||||
|
Py_DECREF(v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
PyErr_Format(PyExc_SystemError,
|
PyErr_Format(PyExc_SystemError,
|
||||||
"no locals found when storing %s",
|
"no locals found when storing %s",
|
||||||
PyObject_REPR(w));
|
PyObject_REPR(w));
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
err = PyDict_SetItem(x, w, v);
|
|
||||||
Py_DECREF(v);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DELETE_NAME:
|
case DELETE_NAME:
|
||||||
w = GETITEM(names, oparg);
|
w = GETITEM(names, oparg);
|
||||||
if ((x = f->f_locals) == NULL) {
|
if ((x = f->f_locals) != NULL) {
|
||||||
PyErr_Format(PyExc_SystemError,
|
|
||||||
"no locals when deleting %s",
|
|
||||||
PyObject_REPR(w));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ((err = PyDict_DelItem(x, w)) != 0)
|
if ((err = PyDict_DelItem(x, w)) != 0)
|
||||||
format_exc_check_arg(PyExc_NameError,
|
format_exc_check_arg(PyExc_NameError,
|
||||||
NAME_ERROR_MSG ,w);
|
NAME_ERROR_MSG ,w);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
PyErr_Format(PyExc_SystemError,
|
||||||
|
"no locals when deleting %s",
|
||||||
|
PyObject_REPR(w));
|
||||||
|
break;
|
||||||
|
|
||||||
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
|
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
|
||||||
case UNPACK_SEQUENCE:
|
case UNPACK_SEQUENCE:
|
||||||
|
@ -1794,7 +1790,7 @@ eval_frame(PyFrameObject *f)
|
||||||
}
|
}
|
||||||
Py_INCREF(x);
|
Py_INCREF(x);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
case LOAD_GLOBAL:
|
case LOAD_GLOBAL:
|
||||||
w = GETITEM(names, oparg);
|
w = GETITEM(names, oparg);
|
||||||
|
@ -1840,16 +1836,16 @@ eval_frame(PyFrameObject *f)
|
||||||
|
|
||||||
case DELETE_FAST:
|
case DELETE_FAST:
|
||||||
x = GETLOCAL(oparg);
|
x = GETLOCAL(oparg);
|
||||||
if (x == NULL) {
|
if (x != NULL) {
|
||||||
|
SETLOCAL(oparg, NULL);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
format_exc_check_arg(
|
format_exc_check_arg(
|
||||||
PyExc_UnboundLocalError,
|
PyExc_UnboundLocalError,
|
||||||
UNBOUNDLOCAL_ERROR_MSG,
|
UNBOUNDLOCAL_ERROR_MSG,
|
||||||
PyTuple_GetItem(co->co_varnames, oparg)
|
PyTuple_GetItem(co->co_varnames, oparg)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
SETLOCAL(oparg, NULL);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
case LOAD_CLOSURE:
|
case LOAD_CLOSURE:
|
||||||
x = freevars[oparg];
|
x = freevars[oparg];
|
||||||
|
@ -1860,7 +1856,10 @@ eval_frame(PyFrameObject *f)
|
||||||
case LOAD_DEREF:
|
case LOAD_DEREF:
|
||||||
x = freevars[oparg];
|
x = freevars[oparg];
|
||||||
w = PyCell_Get(x);
|
w = PyCell_Get(x);
|
||||||
if (w == NULL) {
|
if (w != NULL) {
|
||||||
|
PUSH(w);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
err = -1;
|
err = -1;
|
||||||
/* Don't stomp existing exception */
|
/* Don't stomp existing exception */
|
||||||
if (PyErr_Occurred())
|
if (PyErr_Occurred())
|
||||||
|
@ -1882,9 +1881,6 @@ eval_frame(PyFrameObject *f)
|
||||||
v);
|
v);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
PUSH(w);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case STORE_DEREF:
|
case STORE_DEREF:
|
||||||
w = POP();
|
w = POP();
|
||||||
|
|
Loading…
Reference in New Issue