[Python-checkins] cpython: Enable also ptr==ptr optimization in PyUnicode_Compare()
victor.stinner
python-checkins at python.org
Thu Oct 4 21:58:23 CEST 2012
http://hg.python.org/cpython/rev/5e0a1f116521
changeset: 79468:5e0a1f116521
parent: 79466:a40981be184d
user: Victor Stinner <victor.stinner at gmail.com>
date: Thu Oct 04 21:53:50 2012 +0200
summary:
Enable also ptr==ptr optimization in PyUnicode_Compare()
It was already implemented in PyUnicode_RichCompare()
files:
Include/unicodeobject.h | 3 ++-
Objects/unicodeobject.c | 9 +++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -1951,7 +1951,8 @@
);
/* Compare two strings and return -1, 0, 1 for less than, equal,
- greater than resp. */
+ greater than resp.
+ Raise an exception and return -1 on error. */
PyAPI_FUNC(int) PyUnicode_Compare(
PyObject *left, /* Left string */
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10445,6 +10445,10 @@
void *data1, *data2;
Py_ssize_t len1, len2, i;
+ /* a string is equal to itself */
+ if (str1 == str2)
+ return 0;
+
kind1 = PyUnicode_KIND(str1);
kind2 = PyUnicode_KIND(str2);
data1 = PyUnicode_DATA(str1);
@@ -10531,10 +10535,7 @@
return Py_True;
}
}
- if (left == right)
- result = 0;
- else
- result = unicode_compare(left, right);
+ result = unicode_compare(left, right);
/* Convert the return value to a Boolean */
switch (op) {
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list