summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-11 23:22:22 +0200
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-11 23:22:22 +0200
commit8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe (patch)
treedb00355ce68c1bfaab38405c9400c22f31b6c7db
parentc5af7730e34f15d917730c66076125d4e545f11a (diff)
downloadcpython-git-8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe.tar.gz
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
-rw-r--r--Objects/stringlib/asciilib.h1
-rw-r--r--Objects/stringlib/fastsearch.h10
-rw-r--r--Objects/stringlib/stringdefs.h1
-rw-r--r--Objects/stringlib/ucs1lib.h1
-rw-r--r--Objects/stringlib/ucs2lib.h1
-rw-r--r--Objects/stringlib/ucs4lib.h1
-rw-r--r--Objects/stringlib/undef.h1
-rw-r--r--Objects/stringlib/unicodedefs.h1
8 files changed, 15 insertions, 2 deletions
diff --git a/Objects/stringlib/asciilib.h b/Objects/stringlib/asciilib.h
index 935a9c741c..bfd5d75a3c 100644
--- a/Objects/stringlib/asciilib.h
+++ b/Objects/stringlib/asciilib.h
@@ -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"
diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h
index 33ab6ff94e..085ec6a3d2 100644
--- a/Objects/stringlib/fastsearch.h
+++ b/Objects/stringlib/fastsearch.h
@@ -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);
diff --git a/Objects/stringlib/stringdefs.h b/Objects/stringlib/stringdefs.h
index 96193322c3..41449fce4e 100644
--- a/Objects/stringlib/stringdefs.h
+++ b/Objects/stringlib/stringdefs.h
@@ -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"
diff --git a/Objects/stringlib/ucs1lib.h b/Objects/stringlib/ucs1lib.h
index c0f7adf3ad..0b82a84e97 100644
--- a/Objects/stringlib/ucs1lib.h
+++ b/Objects/stringlib/ucs1lib.h
@@ -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"
diff --git a/Objects/stringlib/ucs2lib.h b/Objects/stringlib/ucs2lib.h
index fc62fb7b3b..18117ef5e6 100644
--- a/Objects/stringlib/ucs2lib.h
+++ b/Objects/stringlib/ucs2lib.h
@@ -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"
diff --git a/Objects/stringlib/ucs4lib.h b/Objects/stringlib/ucs4lib.h
index be1206a6d5..988ddc08d8 100644
--- a/Objects/stringlib/ucs4lib.h
+++ b/Objects/stringlib/ucs4lib.h
@@ -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"
diff --git a/Objects/stringlib/undef.h b/Objects/stringlib/undef.h
index 40b4391cd6..fd87e56d36 100644
--- a/Objects/stringlib/undef.h
+++ b/Objects/stringlib/undef.h
@@ -1,5 +1,6 @@
#undef FASTSEARCH
#undef STRINGLIB
+#undef STRINGLIB_SIZEOF_CHAR
#undef STRINGLIB_CHAR
#undef STRINGLIB_STR
#undef STRINGLIB_LEN
diff --git a/Objects/stringlib/unicodedefs.h b/Objects/stringlib/unicodedefs.h
index 0c40b801e3..5c0761a74c 100644
--- a/Objects/stringlib/unicodedefs.h
+++ b/Objects/stringlib/unicodedefs.h
@@ -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"