summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-04 10:23:05 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-04 10:23:05 (GMT)
commitfd9e44db371f6e097b8756a004ac3783f7fb2df0 (patch)
treee31413b55c0e03f18c43c360cfccd44b93c74468 /Objects/unicodeobject.c
parentc8bc5377ac59c6e6af5c0e925fa0af7d9df7ebc0 (diff)
downloadcpython-fd9e44db371f6e097b8756a004ac3783f7fb2df0.zip
cpython-fd9e44db371f6e097b8756a004ac3783f7fb2df0.tar.gz
cpython-fd9e44db371f6e097b8756a004ac3783f7fb2df0.tar.bz2
Issue #16286: optimize PyUnicode_RichCompare() for identical strings (same
pointer) for any operator, not only Py_EQ and Py_NE. Code of bytes_richcompare() and PyUnicode_RichCompare() is now closer.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 17ae481..f0aff5f 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10534,10 +10534,6 @@ unicode_compare_eq(PyObject *str1, PyObject *str2)
Py_ssize_t len;
int cmp;
- /* a string is equal to itself */
- if (str1 == str2)
- return 1;
-
len = PyUnicode_GET_LENGTH(str1);
if (PyUnicode_GET_LENGTH(str2) != len)
return 0;
@@ -10628,7 +10624,25 @@ PyUnicode_RichCompare(PyObject *left, PyObject *right, int op)
PyUnicode_READY(right) == -1)
return NULL;
- if (op == Py_EQ || op == Py_NE) {
+ if (left == right) {
+ switch (op) {
+ case Py_EQ:
+ case Py_LE:
+ case Py_GE:
+ /* a string is equal to itself */
+ v = Py_True;
+ break;
+ case Py_NE:
+ case Py_LT:
+ case Py_GT:
+ v = Py_False;
+ break;
+ default:
+ PyErr_BadArgument();
+ return NULL;
+ }
+ }
+ else if (op == Py_EQ || op == Py_NE) {
result = unicode_compare_eq(left, right);
result ^= (op == Py_NE);
v = TEST_COND(result);