summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2011-10-11 21:22:22 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2011-10-11 21:22:22 (GMT)
commit8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe (patch)
treedb00355ce68c1bfaab38405c9400c22f31b6c7db /Objects
parentc5af7730e34f15d917730c66076125d4e545f11a (diff)
downloadcpython-8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe.zip
cpython-8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe.tar.gz
cpython-8cc70dcf7020f1e5c286fed5b2a1034f5ba36afe.tar.bz2
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
Diffstat (limited to 'Objects')
-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 935a9c7..bfd5d75a 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 33ab6ff..085ec6a 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 9619332..41449fc 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 c0f7adf..0b82a84 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 fc62fb7..18117ef 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 be1206a..988ddc0 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 40b4391..fd87e56 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 0c40b80..5c0761a 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"