mirror of https://github.com/python/cpython
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.
This commit is contained in:
parent
9fc5981ea2
commit
cd777eaf53
|
@ -10304,8 +10304,19 @@ unicode_compare(PyObject *str1, PyObject *str2)
|
||||||
COMPARE(Py_UCS2, Py_UCS1);
|
COMPARE(Py_UCS2, Py_UCS1);
|
||||||
break;
|
break;
|
||||||
case PyUnicode_2BYTE_KIND:
|
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);
|
COMPARE(Py_UCS2, Py_UCS2);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case PyUnicode_4BYTE_KIND:
|
case PyUnicode_4BYTE_KIND:
|
||||||
COMPARE(Py_UCS2, Py_UCS4);
|
COMPARE(Py_UCS2, Py_UCS4);
|
||||||
break;
|
break;
|
||||||
|
@ -10324,8 +10335,19 @@ unicode_compare(PyObject *str1, PyObject *str2)
|
||||||
COMPARE(Py_UCS4, Py_UCS2);
|
COMPARE(Py_UCS4, Py_UCS2);
|
||||||
break;
|
break;
|
||||||
case PyUnicode_4BYTE_KIND:
|
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);
|
COMPARE(Py_UCS4, Py_UCS4);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -645,6 +645,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
|
||||||
#define HAVE_WCSXFRM 1
|
#define HAVE_WCSXFRM 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `wmemcmp' function. */
|
||||||
|
#define HAVE_WMEMCMP 1
|
||||||
|
|
||||||
/* Define if the zlib library has inflateCopy */
|
/* Define if the zlib library has inflateCopy */
|
||||||
#define HAVE_ZLIB_COPY 1
|
#define HAVE_ZLIB_COPY 1
|
||||||
|
|
||||||
|
|
|
@ -10273,7 +10273,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
|
||||||
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
|
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
|
||||||
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
||||||
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
|
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
|
||||||
wcscoll wcsftime wcsxfrm writev _getpty
|
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty
|
||||||
do :
|
do :
|
||||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||||
|
|
|
@ -2816,7 +2816,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
|
||||||
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
|
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \
|
||||||
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
|
||||||
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
|
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
|
||||||
wcscoll wcsftime wcsxfrm writev _getpty)
|
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty)
|
||||||
|
|
||||||
AC_CHECK_DECL(dirfd,
|
AC_CHECK_DECL(dirfd,
|
||||||
AC_DEFINE(HAVE_DIRFD, 1,
|
AC_DEFINE(HAVE_DIRFD, 1,
|
||||||
|
|
|
@ -1118,6 +1118,9 @@
|
||||||
/* Define to 1 if you have the `wcsxfrm' function. */
|
/* Define to 1 if you have the `wcsxfrm' function. */
|
||||||
#undef HAVE_WCSXFRM
|
#undef HAVE_WCSXFRM
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `wmemcmp' function. */
|
||||||
|
#undef HAVE_WMEMCMP
|
||||||
|
|
||||||
/* Define if tzset() actually switches the local timezone in a meaningful way.
|
/* Define if tzset() actually switches the local timezone in a meaningful way.
|
||||||
*/
|
*/
|
||||||
#undef HAVE_WORKING_TZSET
|
#undef HAVE_WORKING_TZSET
|
||||||
|
@ -1190,9 +1193,6 @@
|
||||||
/* Define if setpgrp() must be called as setpgrp(0, 0). */
|
/* Define if setpgrp() must be called as setpgrp(0, 0). */
|
||||||
#undef SETPGRP_HAVE_ARG
|
#undef SETPGRP_HAVE_ARG
|
||||||
|
|
||||||
/* Define this to be extension of shared libraries (including the dot!). */
|
|
||||||
#undef SHLIB_EXT
|
|
||||||
|
|
||||||
/* Define if i>>j for signed int i does not extend the sign bit when i < 0 */
|
/* Define if i>>j for signed int i does not extend the sign bit when i < 0 */
|
||||||
#undef SIGNED_RIGHT_SHIFT_ZERO_FILLS
|
#undef SIGNED_RIGHT_SHIFT_ZERO_FILLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue