Skip to content

Commit f068f94

Browse files
committed
Merged revisions 77469-77470 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77469 | antoine.pitrou | 2010-01-13 14:43:37 +0100 (mer., 13 janv. 2010) | 3 lines Test commit to try to diagnose failures of the IA-64 buildbot ........ r77470 | antoine.pitrou | 2010-01-13 15:01:26 +0100 (mer., 13 janv. 2010) | 3 lines Sanitize bloom filter macros ........
1 parent 72f4d64 commit f068f94

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

Objects/stringlib/fastsearch.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,27 @@
1818
#define FAST_SEARCH 1
1919
#define FAST_RSEARCH 2
2020

21-
#define BLOOM_ADD(mask, ch) ((mask |= (1 << ((ch) & (LONG_BIT - 1)))))
22-
#define BLOOM(mask, ch) ((mask & (1 << ((ch) & (LONG_BIT - 1)))))
21+
#if LONG_BIT >= 128
22+
#define STRINGLIB_BLOOM_WIDTH 128
23+
#elif LONG_BIT >= 64
24+
#define STRINGLIB_BLOOM_WIDTH 64
25+
#elif LONG_BIT >= 32
26+
#define STRINGLIB_BLOOM_WIDTH 32
27+
#else
28+
#error "LONG_BIT is smaller than 32"
29+
#endif
30+
31+
#define STRINGLIB_BLOOM_ADD(mask, ch) \
32+
((mask |= (1UL << ((ch) & (STRINGLIB_BLOOM_WIDTH -1)))))
33+
#define STRINGLIB_BLOOM(mask, ch) \
34+
((mask & (1UL << ((ch) & (STRINGLIB_BLOOM_WIDTH -1)))))
2335

2436
Py_LOCAL_INLINE(Py_ssize_t)
2537
fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
2638
const STRINGLIB_CHAR* p, Py_ssize_t m,
2739
Py_ssize_t maxcount, int mode)
2840
{
29-
long mask;
41+
unsigned long mask;
3042
Py_ssize_t skip, count = 0;
3143
Py_ssize_t i, j, mlast, w;
3244

@@ -70,12 +82,12 @@ fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
7082

7183
/* process pattern[:-1] */
7284
for (i = 0; i < mlast; i++) {
73-
BLOOM_ADD(mask, p[i]);
85+
STRINGLIB_BLOOM_ADD(mask, p[i]);
7486
if (p[i] == p[mlast])
7587
skip = mlast - i - 1;
7688
}
7789
/* process pattern[-1] outside the loop */
78-
BLOOM_ADD(mask, p[mlast]);
90+
STRINGLIB_BLOOM_ADD(mask, p[mlast]);
7991

8092
for (i = 0; i <= w; i++) {
8193
/* note: using mlast in the skip path slows things down on x86 */
@@ -95,13 +107,13 @@ fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
95107
continue;
96108
}
97109
/* miss: check if next character is part of pattern */
98-
if (!BLOOM(mask, s[i+m]))
110+
if (!STRINGLIB_BLOOM(mask, s[i+m]))
99111
i = i + m;
100112
else
101113
i = i + skip;
102114
} else {
103115
/* skip: check if next character is part of pattern */
104-
if (!BLOOM(mask, s[i+m]))
116+
if (!STRINGLIB_BLOOM(mask, s[i+m]))
105117
i = i + m;
106118
}
107119
}
@@ -110,10 +122,10 @@ fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
110122
/* create compressed boyer-moore delta 1 table */
111123

112124
/* process pattern[0] outside the loop */
113-
BLOOM_ADD(mask, p[0]);
125+
STRINGLIB_BLOOM_ADD(mask, p[0]);
114126
/* process pattern[:0:-1] */
115127
for (i = mlast; i > 0; i--) {
116-
BLOOM_ADD(mask, p[i]);
128+
STRINGLIB_BLOOM_ADD(mask, p[i]);
117129
if (p[i] == p[0])
118130
skip = i - 1;
119131
}
@@ -128,13 +140,13 @@ fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n,
128140
/* got a match! */
129141
return i;
130142
/* miss: check if previous character is part of pattern */
131-
if (!BLOOM(mask, s[i-1]))
143+
if (!STRINGLIB_BLOOM(mask, s[i-1]))
132144
i = i - m;
133145
else
134146
i = i - skip;
135147
} else {
136148
/* skip: check if previous character is part of pattern */
137-
if (!BLOOM(mask, s[i-1]))
149+
if (!STRINGLIB_BLOOM(mask, s[i-1]))
138150
i = i - m;
139151
}
140152
}

Objects/unicodeobject.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,22 @@ PyUnicode_GetMax(void)
206206

207207
/* the linebreak mask is set up by Unicode_Init below */
208208

209+
#if LONG_BIT >= 128
210+
#define BLOOM_WIDTH 128
211+
#elif LONG_BIT >= 64
212+
#define BLOOM_WIDTH 64
213+
#elif LONG_BIT >= 32
214+
#define BLOOM_WIDTH 32
215+
#else
216+
#error "LONG_BIT is smaller than 32"
217+
#endif
218+
209219
#define BLOOM_MASK unsigned long
210220

211221
static BLOOM_MASK bloom_linebreak;
212222

213-
#define BLOOM_ADD(mask, ch) ((mask |= (1 << ((ch) & (LONG_BIT - 1)))))
214-
#define BLOOM(mask, ch) ((mask & (1 << ((ch) & (LONG_BIT - 1)))))
223+
#define BLOOM_ADD(mask, ch) ((mask |= (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
224+
#define BLOOM(mask, ch) ((mask & (1UL << ((ch) & (BLOOM_WIDTH - 1)))))
215225

216226
#define BLOOM_LINEBREAK(ch) \
217227
((ch) < 128U ? ascii_linebreak[(ch)] : \
@@ -221,7 +231,7 @@ Py_LOCAL_INLINE(BLOOM_MASK) make_bloom_mask(Py_UNICODE* ptr, Py_ssize_t len)
221231
{
222232
/* calculate simple bloom-style bitmask for a given unicode string */
223233

224-
long mask;
234+
BLOOM_MASK mask;
225235
Py_ssize_t i;
226236

227237
mask = 0;

0 commit comments

Comments
 (0)