summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-04-08 20:43:44 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-04-08 20:43:44 (GMT)
commitcd777eaf53e438e2c3b7aab384f18d56b262bc0b (patch)
tree5a95e3a6567bbf8dd559a73124c866d91360b35b /Objects/unicodeobject.c
parent9fc5981ea2ee722a8012e67aaa5cf6d6cae99bb1 (diff)
downloadcpython-cd777eaf53e438e2c3b7aab384f18d56b262bc0b.zip
cpython-cd777eaf53e438e2c3b7aab384f18d56b262bc0b.tar.gz
cpython-cd777eaf53e438e2c3b7aab384f18d56b262bc0b.tar.bz2
Issue #17615: Comparing two Unicode strings now uses wmemcmp() when possible
wmemcmp() is twice faster than a dummy loop (342 usec vs 744 usec) on Fedora 18/x86_64, GCC 4.7.2.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index d450b4d..e9153c0 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -10304,8 +10304,19 @@ unicode_compare(PyObject *str1, PyObject *str2)
COMPARE(Py_UCS2, Py_UCS1);
break;
case PyUnicode_2BYTE_KIND:
+ {
+#if defined(HAVE_WMEMCMP) && SIZEOF_WCHAR_T == 2
+ int cmp = wmemcmp((wchar_t *)data1, (wchar_t *)data2, len);
+ /* normalize result of wmemcmp() into the range [-1; 1] */
+ if (cmp < 0)
+ return -1;
+ if (cmp > 0)
+ return 1;
+#else
COMPARE(Py_UCS2, Py_UCS2);
+#endif
break;
+ }
case PyUnicode_4BYTE_KIND:
COMPARE(Py_UCS2, Py_UCS4);
break;
@@ -10324,8 +10335,19 @@ unicode_compare(PyObject *str1, PyObject *str2)
COMPARE(Py_UCS4, Py_UCS2);
break;
case PyUnicode_4BYTE_KIND:
+ {
+#if defined(HAVE_WMEMCMP) && SIZEOF_WCHAR_T == 4
+ int cmp = wmemcmp((wchar_t *)data1, (wchar_t *)data2, len);
+ /* normalize result of wmemcmp() into the range [-1; 1] */
+ if (cmp < 0)
+ return -1;
+ if (cmp > 0)
+ return 1;
+#else
COMPARE(Py_UCS4, Py_UCS4);
+#endif
break;
+ }
default:
assert(0);
}