[Python-checkins] python/dist/src/Python ceval.c,2.346,2.347
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Sat, 18 Jan 2003 21:08:16 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv20475
Modified Files:
ceval.c
Log Message:
SF patch #670367: Micro-optimizations for ceval.c
Make the code slightly shorter, faster, and easier to
read.
* Eliminate unused DUP_TOPX code for x==1.
compile.c always generates DUP_TOP instead.
* Since only two cases remain for DUP_TOPX, replace
the switch-case with if-elseif.
* The in-lined integer compare does a CheckExact on
both arguments. Since the second is a little more
likely to fail, test it first.
* The switch-case for IS/IS_NOT and IN/NOT_IN can
separate the regular and inverted cases with no
additional work. For all four paths, saves a test and
jump.
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.346
retrieving revision 2.347
diff -C2 -d -r2.346 -r2.347
*** ceval.c 14 Jan 2003 12:43:10 -0000 2.346
--- ceval.c 19 Jan 2003 05:08:13 -0000 2.347
***************
*** 856,867 ****
case DUP_TOPX:
! switch (oparg) {
! case 1:
! x = TOP();
! Py_INCREF(x);
! STACKADJ(1);
! SET_TOP(x);
! continue;
! case 2:
x = TOP();
Py_INCREF(x);
--- 856,860 ----
case DUP_TOPX:
! if (oparg == 2) {
x = TOP();
Py_INCREF(x);
***************
*** 872,876 ****
SET_SECOND(w);
continue;
! case 3:
x = TOP();
Py_INCREF(x);
--- 865,869 ----
SET_SECOND(w);
continue;
! } else if (oparg == 3) {
x = TOP();
Py_INCREF(x);
***************
*** 884,891 ****
SET_THIRD(v);
continue;
- default:
- Py_FatalError("invalid argument to DUP_TOPX"
- " (bytecode corruption?)");
}
break;
--- 877,883 ----
SET_THIRD(v);
continue;
}
+ Py_FatalError("invalid argument to DUP_TOPX"
+ " (bytecode corruption?)");
break;
***************
*** 1843,1847 ****
w = POP();
v = TOP();
! if (PyInt_CheckExact(v) && PyInt_CheckExact(w)) {
/* INLINE: cmp(int, int) */
register long a, b;
--- 1835,1839 ----
w = POP();
v = TOP();
! if (PyInt_CheckExact(w) && PyInt_CheckExact(v)) {
/* INLINE: cmp(int, int) */
register long a, b;
***************
*** 3582,3597 ****
switch (op) {
case PyCmp_IS:
- case PyCmp_IS_NOT:
res = (v == w);
! if (op == (int) PyCmp_IS_NOT)
! res = !res;
break;
case PyCmp_IN:
case PyCmp_NOT_IN:
res = PySequence_Contains(w, v);
if (res < 0)
return NULL;
! if (op == (int) PyCmp_NOT_IN)
! res = !res;
break;
case PyCmp_EXC_MATCH:
--- 3574,3592 ----
switch (op) {
case PyCmp_IS:
res = (v == w);
! break;
! case PyCmp_IS_NOT:
! res = (v != w);
break;
case PyCmp_IN:
+ res = PySequence_Contains(w, v);
+ if (res < 0)
+ return NULL;
+ break;
case PyCmp_NOT_IN:
res = PySequence_Contains(w, v);
if (res < 0)
return NULL;
! res = !res;
break;
case PyCmp_EXC_MATCH: