@@ -80,12 +80,12 @@ class StringSearchBase {
80
80
static const int kBMMinPatternLength = 8 ;
81
81
82
82
// Store for the BoyerMoore(Horspool) bad char shift table.
83
- static int kBadCharShiftTable [kUC16AlphabetSize ];
83
+ int bad_char_shift_table_ [kUC16AlphabetSize ];
84
84
// Store for the BoyerMoore good suffix shift table.
85
- static int kGoodSuffixShiftTable [kBMMaxShift + 1 ];
85
+ int good_suffix_shift_table_ [kBMMaxShift + 1 ];
86
86
// Table used temporarily while building the BoyerMoore good suffix
87
87
// shift table.
88
- static int kSuffixTable [kBMMaxShift + 1 ];
88
+ int suffix_table_ [kBMMaxShift + 1 ];
89
89
};
90
90
91
91
template <typename Char>
@@ -152,26 +152,6 @@ class StringSearch : private StringSearchBase {
152
152
return bad_char_occurrence[equiv_class];
153
153
}
154
154
155
- // Store for the BoyerMoore(Horspool) bad char shift table.
156
- // Return a table covering the last kBMMaxShift+1 positions of
157
- // pattern.
158
- int * bad_char_table () { return kBadCharShiftTable ; }
159
-
160
- // Store for the BoyerMoore good suffix shift table.
161
- int * good_suffix_shift_table () {
162
- // Return biased pointer that maps the range [start_..pattern_.length()
163
- // to the kGoodSuffixShiftTable array.
164
- return kGoodSuffixShiftTable - start_;
165
- }
166
-
167
- // Table used temporarily while building the BoyerMoore good suffix
168
- // shift table.
169
- int * suffix_table () {
170
- // Return biased pointer that maps the range [start_..pattern_.length()
171
- // to the kSuffixTable array.
172
- return kSuffixTable - start_;
173
- }
174
-
175
155
// The pattern to search for.
176
156
Vector pattern_;
177
157
// Pointer to implementation of the search.
@@ -345,8 +325,8 @@ size_t StringSearch<Char>::BoyerMooreSearch(
345
325
// Only preprocess at most kBMMaxShift last characters of pattern.
346
326
size_t start = start_;
347
327
348
- int * bad_char_occurrence = bad_char_table () ;
349
- int * good_suffix_shift = good_suffix_shift_table () ;
328
+ int * bad_char_occurrence = bad_char_shift_table_ ;
329
+ int * good_suffix_shift = good_suffix_shift_table_ - start_ ;
350
330
351
331
Char last_char = pattern_[pattern_length - 1 ];
352
332
size_t index = start_index;
@@ -397,8 +377,8 @@ void StringSearch<Char>::PopulateBoyerMooreTable() {
397
377
398
378
// Biased tables so that we can use pattern indices as table indices,
399
379
// even if we only cover the part of the pattern from offset start.
400
- int * shift_table = good_suffix_shift_table () ;
401
- int * suffix_table = this -> suffix_table () ;
380
+ int * shift_table = good_suffix_shift_table_ - start_ ;
381
+ int * suffix_table = suffix_table_ - start_ ;
402
382
403
383
// Initialize table.
404
384
for (size_t i = start; i < pattern_length; i++) {
@@ -462,7 +442,7 @@ size_t StringSearch<Char>::BoyerMooreHorspoolSearch(
462
442
size_t start_index) {
463
443
const size_t subject_length = subject.length ();
464
444
const size_t pattern_length = pattern_.length ();
465
- int * char_occurrences = bad_char_table () ;
445
+ int * char_occurrences = bad_char_shift_table_ ;
466
446
int64_t badness = -pattern_length;
467
447
468
448
// How bad we are doing without a good-suffix table.
@@ -511,7 +491,7 @@ template <typename Char>
511
491
void StringSearch<Char>::PopulateBoyerMooreHorspoolTable() {
512
492
const size_t pattern_length = pattern_.length ();
513
493
514
- int * bad_char_occurrence = bad_char_table () ;
494
+ int * bad_char_occurrence = bad_char_shift_table_ ;
515
495
516
496
// Only preprocess at most kBMMaxShift last characters of pattern.
517
497
const size_t start = start_;
0 commit comments