@@ -442,9 +442,14 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack,
442
442
{
443
443
// Crochemore and Perrin's (1991) Two-Way algorithm.
444
444
// See http://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
445
- // Needle
446
445
const Py_ssize_t len_needle = pw -> len_needle ;
447
446
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
+ }
448
453
// Cut & Period
449
454
const Py_ssize_t cut = pw -> cut ;
450
455
// const Py_ssize_t cut_idx = reversed ? len_needle - cut : cut;
@@ -455,13 +460,6 @@ STRINGLIB(_two_way)(const STRINGLIB_CHAR *haystack,
455
460
SHIFT_TYPE * table = pw -> table ;
456
461
const STRINGLIB_CHAR * window ;
457
462
// 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
- }
465
463
// Prepare
466
464
Py_ssize_t count = 0 ;
467
465
Py_ssize_t gap = pw -> gap ;
@@ -743,8 +741,9 @@ STRINGLIB(two_way_find)(const STRINGLIB_CHAR *haystack,
743
741
const STRINGLIB_CHAR * needle ,
744
742
Py_ssize_t len_needle ,
745
743
Py_ssize_t maxcount ,
746
- int mode , int dir )
744
+ int mode , int direction )
747
745
{
746
+ int dir = direction < 0 ? -1 : 1 ;
748
747
STRINGLIB (prework ) pw ;
749
748
(& pw )-> needle = needle ;
750
749
(& pw )-> len_needle = len_needle ;
@@ -849,17 +848,17 @@ STRINGLIB(horspool_find)(const STRINGLIB_CHAR* s, Py_ssize_t n,
849
848
shift = Py_MAX (table [s_last & TABLE_MASK ], 1 );
850
849
}
851
850
}
852
- assert (s_last == p_last );
853
851
}
854
852
else {
855
853
shift = table [s_last & TABLE_MASK ];
856
- assert ((s_last & TABLE_MASK ) == (p_last & TABLE_MASK ));
857
854
}
858
855
if (shift != 0 ) {
859
856
LOG ("Shift %ld\n" , shift );
860
857
i += shift ;
861
858
continue ;
862
859
}
860
+ // assert(s_last == p_last); // true_gap
861
+ // assert((s_last & TABLE_MASK) == (p_last & TABLE_MASK)); // else
863
862
j_off = ip - p_end ;
864
863
for (j = 0 ; j < j_stop ; j ++ ) {
865
864
ihits ++ ;
0 commit comments