[Python-checkins] python/dist/src/Python ceval.c,2.391,2.392
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Wed Apr 7 07:39:24 EDT 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4752
Modified Files:
ceval.c
Log Message:
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
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.391
retrieving revision 2.392
diff -C2 -d -r2.391 -r2.392
*** ceval.c 6 Apr 2004 10:11:10 -0000 2.391
--- ceval.c 7 Apr 2004 11:39:21 -0000 2.392
***************
*** 1156,1171 ****
if (i < 0)
i += PyList_GET_SIZE(v);
! if (i < 0 ||
! i >= PyList_GET_SIZE(v)) {
! PyErr_SetString(PyExc_IndexError,
! "list index out of range");
! x = NULL;
! }
! else {
x = PyList_GET_ITEM(v, i);
Py_INCREF(x);
}
}
else
x = PyObject_GetItem(v, w);
Py_DECREF(v);
--- 1156,1168 ----
if (i < 0)
i += PyList_GET_SIZE(v);
! if (i >= 0 && i < PyList_GET_SIZE(v)) {
x = PyList_GET_ITEM(v, i);
Py_INCREF(x);
}
+ else
+ goto slow_get;
}
else
+ slow_get:
x = PyObject_GetItem(v, w);
Py_DECREF(v);
***************
*** 1609,1619 ****
case LOAD_LOCALS:
! if ((x = f->f_locals) == NULL) {
! PyErr_SetString(PyExc_SystemError,
! "no locals");
! break;
}
! Py_INCREF(x);
! PUSH(x);
break;
--- 1606,1615 ----
case LOAD_LOCALS:
! if ((x = f->f_locals) != NULL) {
! Py_INCREF(x);
! PUSH(x);
! continue;
}
! PyErr_SetString(PyExc_SystemError, "no locals");
break;
***************
*** 1688,1712 ****
w = GETITEM(names, oparg);
v = POP();
! if ((x = f->f_locals) == NULL) {
! PyErr_Format(PyExc_SystemError,
! "no locals found when storing %s",
! PyObject_REPR(w));
break;
}
! err = PyDict_SetItem(x, w, v);
! Py_DECREF(v);
break;
case DELETE_NAME:
w = GETITEM(names, oparg);
! 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)
! format_exc_check_arg(PyExc_NameError,
! NAME_ERROR_MSG ,w);
break;
--- 1684,1708 ----
w = GETITEM(names, oparg);
v = POP();
! if ((x = f->f_locals) != NULL) {
! err = PyDict_SetItem(x, w, v);
! Py_DECREF(v);
break;
}
! PyErr_Format(PyExc_SystemError,
! "no locals found when storing %s",
! PyObject_REPR(w));
break;
case DELETE_NAME:
w = GETITEM(names, oparg);
! if ((x = f->f_locals) != NULL) {
! if ((err = PyDict_DelItem(x, w)) != 0)
! format_exc_check_arg(PyExc_NameError,
! NAME_ERROR_MSG ,w);
break;
}
! PyErr_Format(PyExc_SystemError,
! "no locals when deleting %s",
! PyObject_REPR(w));
break;
***************
*** 1795,1799 ****
Py_INCREF(x);
PUSH(x);
! break;
case LOAD_GLOBAL:
--- 1791,1795 ----
Py_INCREF(x);
PUSH(x);
! continue;
case LOAD_GLOBAL:
***************
*** 1841,1854 ****
case DELETE_FAST:
x = GETLOCAL(oparg);
! if (x == NULL) {
! format_exc_check_arg(
! PyExc_UnboundLocalError,
! UNBOUNDLOCAL_ERROR_MSG,
! PyTuple_GetItem(co->co_varnames, oparg)
! );
! break;
}
! SETLOCAL(oparg, NULL);
! continue;
case LOAD_CLOSURE:
--- 1837,1850 ----
case DELETE_FAST:
x = GETLOCAL(oparg);
! if (x != NULL) {
! SETLOCAL(oparg, NULL);
! continue;
}
! format_exc_check_arg(
! PyExc_UnboundLocalError,
! UNBOUNDLOCAL_ERROR_MSG,
! PyTuple_GetItem(co->co_varnames, oparg)
! );
! break;
case LOAD_CLOSURE:
***************
*** 1861,1888 ****
x = freevars[oparg];
w = PyCell_Get(x);
! if (w == NULL) {
! err = -1;
! /* Don't stomp existing exception */
! if (PyErr_Occurred())
! break;
! if (oparg < f->f_ncells) {
! v = PyTuple_GetItem(co->co_cellvars,
! oparg);
! format_exc_check_arg(
! PyExc_UnboundLocalError,
! UNBOUNDLOCAL_ERROR_MSG,
! v);
! } else {
! v = PyTuple_GetItem(
! co->co_freevars,
! oparg - f->f_ncells);
! format_exc_check_arg(
! PyExc_NameError,
! UNBOUNDFREE_ERROR_MSG,
! v);
! }
break;
}
- PUSH(w);
break;
--- 1857,1884 ----
x = freevars[oparg];
w = PyCell_Get(x);
! if (w != NULL) {
! PUSH(w);
! continue;
! }
! err = -1;
! /* Don't stomp existing exception */
! if (PyErr_Occurred())
break;
+ if (oparg < f->f_ncells) {
+ v = PyTuple_GetItem(co->co_cellvars,
+ oparg);
+ format_exc_check_arg(
+ PyExc_UnboundLocalError,
+ UNBOUNDLOCAL_ERROR_MSG,
+ v);
+ } else {
+ v = PyTuple_GetItem(
+ co->co_freevars,
+ oparg - f->f_ncells);
+ format_exc_check_arg(
+ PyExc_NameError,
+ UNBOUNDFREE_ERROR_MSG,
+ v);
}
break;
More information about the Python-checkins
mailing list