diff options
author | Marc-André Lemburg <mal@egenix.com> | 2001-11-07 14:54:49 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2001-11-07 14:54:49 (GMT) |
commit | c52d713b7a324b9ed29ba75f438bf11b96953e41 (patch) | |
tree | 5343a6ea46eebd237dd0d80b1b7aaa3d88afc840 | |
parent | f0b11d28937c826054f662b4958d3d637bf42fd0 (diff) | |
download | cpython-c52d713b7a324b9ed29ba75f438bf11b96953e41.zip cpython-c52d713b7a324b9ed29ba75f438bf11b96953e41.tar.gz cpython-c52d713b7a324b9ed29ba75f438bf11b96953e41.tar.bz2 |
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).
-rw-r--r-- | Python/ceval.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index b707734..34b4cb9 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1778,6 +1778,21 @@ eval_frame(PyFrameObject *f) x = res ? Py_True : Py_False; 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: x = cmp_outcome(oparg, v, w); |