mirror of https://github.com/python/cpython
Fix fastsearch for UCS2 and UCS4
* If needle is 0, try (p[0] >> 16) & 0xff for UCS4 * Disable fastsearch_memchr_1char() if needle is zero for UCS2 and UCS4
This commit is contained in:
parent
c5af7730e3
commit
8cc70dcf70
|
@ -6,6 +6,7 @@
|
|||
#define FASTSEARCH asciilib_fastsearch
|
||||
#define STRINGLIB(F) asciilib_##F
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 1
|
||||
#define STRINGLIB_CHAR Py_UCS1
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
|
|
|
@ -115,11 +115,17 @@ FASTSEARCH(const STRINGLIB_CHAR* s, Py_ssize_t n,
|
|||
unsigned char needle;
|
||||
int use_needle = 1;
|
||||
needle = p[0] & 0xff;
|
||||
if (needle == 0 && sizeof(STRINGLIB_CHAR) > 1) {
|
||||
#if STRINGLIB_SIZEOF_CHAR > 1
|
||||
if (needle == 0) {
|
||||
needle = (p[0] >> 8) & 0xff;
|
||||
if (needle >= 32)
|
||||
#if STRINGLIB_SIZEOF_CHAR > 2
|
||||
if (needle == 0)
|
||||
needle = (p[0] >> 16) & 0xff;
|
||||
#endif
|
||||
if (needle >= 32 || needle == 0)
|
||||
use_needle = 0;
|
||||
}
|
||||
#endif
|
||||
if (use_needle)
|
||||
return STRINGLIB(fastsearch_memchr_1char)
|
||||
(s, n, p[0], needle, maxcount, mode);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define FASTSEARCH fastsearch
|
||||
#define STRINGLIB(F) stringlib_##F
|
||||
#define STRINGLIB_OBJECT PyBytesObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 1
|
||||
#define STRINGLIB_CHAR char
|
||||
#define STRINGLIB_TYPE_NAME "string"
|
||||
#define STRINGLIB_PARSE_CODE "S"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define FASTSEARCH ucs1lib_fastsearch
|
||||
#define STRINGLIB(F) ucs1lib_##F
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 1
|
||||
#define STRINGLIB_CHAR Py_UCS1
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define FASTSEARCH ucs2lib_fastsearch
|
||||
#define STRINGLIB(F) ucs2lib_##F
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 2
|
||||
#define STRINGLIB_CHAR Py_UCS2
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define FASTSEARCH ucs4lib_fastsearch
|
||||
#define STRINGLIB(F) ucs4lib_##F
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR 4
|
||||
#define STRINGLIB_CHAR Py_UCS4
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#undef FASTSEARCH
|
||||
#undef STRINGLIB
|
||||
#undef STRINGLIB_SIZEOF_CHAR
|
||||
#undef STRINGLIB_CHAR
|
||||
#undef STRINGLIB_STR
|
||||
#undef STRINGLIB_LEN
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#define FASTSEARCH fastsearch
|
||||
#define STRINGLIB(F) stringlib_##F
|
||||
#define STRINGLIB_OBJECT PyUnicodeObject
|
||||
#define STRINGLIB_SIZEOF_CHAR Py_UNICODE_SIZE
|
||||
#define STRINGLIB_CHAR Py_UNICODE
|
||||
#define STRINGLIB_TYPE_NAME "unicode"
|
||||
#define STRINGLIB_PARSE_CODE "U"
|
||||
|
|
Loading…
Reference in New Issue