Skip to content

Commit 982b510

Browse files
committed
fix assertions
1 parent 1b9bdc9 commit 982b510

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

Objects/stringlib/fastsearch.h

+10-11
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,14 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack,
442442
{
443443
// Crochemore and Perrin's (1991) Two-Way algorithm.
444444
// See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
445-
// Needle
446445
const Py_ssize_t len_needle = pw->len_needle;
447446
const STRINGLIB_CHAR *const needle = pw->needle;
447+
if (mode == FAST_COUNT){
448+
LOG("Two-way Counting \"%s\" in \"%s\".\n", needle, haystack);
449+
}
450+
else {
451+
LOG("Two-way Finding \"%s\" in \"%s\".\n", needle, haystack);
452+
}
448453
// Cut & Period
449454
const Py_ssize_t cut = pw->cut;
450455
// const Py_ssize_t cut_idx = reversed ? len_needle - cut : cut;
@@ -455,13 +460,6 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack,
455460
SHIFT_TYPE *table = pw->table;
456461
const STRINGLIB_CHAR *window;
457462
// Log
458-
LOG("===== Two-way: \"%s\" in \"%s\". =====\n", needle, haystack);
459-
if (mode == FAST_COUNT){
460-
LOG("###### Counting \"%s\" in \"%s\".\n", needle, haystack);
461-
}
462-
else {
463-
LOG("###### Finding \"%s\" in \"%s\".\n", needle, haystack);
464-
}
465463
// Prepare
466464
Py_ssize_t count = 0;
467465
Py_ssize_t gap = pw->gap;
@@ -743,8 +741,9 @@ STRINGLIB(two_way_find)(const STRINGLIB_CHAR *haystack,
743741
const STRINGLIB_CHAR *needle,
744742
Py_ssize_t len_needle,
745743
Py_ssize_t maxcount,
746-
int mode, int dir)
744+
int mode, int direction)
747745
{
746+
int dir = direction < 0 ? -1 : 1;
748747
STRINGLIB(prework) pw;
749748
(&pw)->needle = needle;
750749
(&pw)->len_needle = len_needle;
@@ -849,17 +848,17 @@ STRINGLIB(horspool_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
849848
shift = Py_MAX(table[s_last & TABLE_MASK], 1);
850849
}
851850
}
852-
assert(s_last == p_last);
853851
}
854852
else {
855853
shift = table[s_last & TABLE_MASK];
856-
assert((s_last & TABLE_MASK) == (p_last & TABLE_MASK));
857854
}
858855
if (shift != 0) {
859856
LOG("Shift %ld\n", shift);
860857
i += shift;
861858
continue;
862859
}
860+
// assert(s_last == p_last); // true_gap
861+
// assert((s_last & TABLE_MASK) == (p_last & TABLE_MASK)); // else
863862
j_off = ip - p_end;
864863
for (j = 0; j < j_stop; j++) {
865864
ihits++;

0 commit comments

Comments
 (0)