[Python-checkins] CVS: python/dist/src/Python ceval.c,2.287,2.288
M.-A. Lemburg
lemburg@users.sourceforge.net
Wed, 07 Nov 2001 06:54:51 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv19062/Python
Modified Files:
ceval.c
Log Message:
Add fast-path for comparing interned (true) string objects.
This patch boosts performance for comparing identical string object
by some 20% on my machine while not causing any noticable slow-down
for other operations (according to tests done with pybench).
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.287
retrieving revision 2.288
diff -C2 -d -r2.287 -r2.288
*** ceval.c 2001/10/18 20:49:35 2.287
--- ceval.c 2001/11/07 14:54:49 2.288
***************
*** 1779,1782 ****
--- 1779,1797 ----
Py_INCREF(x);
}
+ else if (v == w && PyString_CheckExact(v)) {
+ /* Fast-path for comparing interned strings */
+ switch (oparg) {
+ case EQ: x = Py_True; break;
+ case LE: x = Py_True; break;
+ case GE: x = Py_True; break;
+ case NE: x = Py_False; break;
+ case GT: x = Py_False; break;
+ case LT: x = Py_False; break;
+ case IS: x = Py_True; break;
+ case IS_NOT: x = Py_False; break;
+ default: goto slow_compare;
+ }
+ Py_INCREF(x);
+ }
else {
slow_compare: