Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 43ec938

Browse filesBrowse files
addaleaxtargos
authored andcommitted
src: remove static variables from string_search
These variables can as well be stack-allocated. This avoids relying on global state that is not protected by mutexes. Thanks to Stephen Belanger for reviewing this change in its original PR. Refs: ayojs/ayo#82 PR-URL: #20541 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent f69a823 commit 43ec938
Copy full SHA for 43ec938

File tree

Expand file treeCollapse file tree

3 files changed

+9
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+9
-41
lines changed
Open diff view settings
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@
344344
'src/spawn_sync.cc',
345345
'src/string_bytes.cc',
346346
'src/string_decoder.cc',
347-
'src/string_search.cc',
348347
'src/stream_base.cc',
349348
'src/stream_pipe.cc',
350349
'src/stream_wrap.cc',
Collapse file

‎src/string_search.cc‎

Copy file name to clipboardExpand all lines: src/string_search.cc
-11Lines changed: 0 additions & 11 deletions
This file was deleted.
Collapse file

‎src/string_search.h‎

Copy file name to clipboardExpand all lines: src/string_search.h
+9-29Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ class StringSearchBase {
8080
static const int kBMMinPatternLength = 8;
8181

8282
// Store for the BoyerMoore(Horspool) bad char shift table.
83-
static int kBadCharShiftTable[kUC16AlphabetSize];
83+
int bad_char_shift_table_[kUC16AlphabetSize];
8484
// Store for the BoyerMoore good suffix shift table.
85-
static int kGoodSuffixShiftTable[kBMMaxShift + 1];
85+
int good_suffix_shift_table_[kBMMaxShift + 1];
8686
// Table used temporarily while building the BoyerMoore good suffix
8787
// shift table.
88-
static int kSuffixTable[kBMMaxShift + 1];
88+
int suffix_table_[kBMMaxShift + 1];
8989
};
9090

9191
template <typename Char>
@@ -152,26 +152,6 @@ class StringSearch : private StringSearchBase {
152152
return bad_char_occurrence[equiv_class];
153153
}
154154

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-
175155
// The pattern to search for.
176156
Vector pattern_;
177157
// Pointer to implementation of the search.
@@ -345,8 +325,8 @@ size_t StringSearch<Char>::BoyerMooreSearch(
345325
// Only preprocess at most kBMMaxShift last characters of pattern.
346326
size_t start = start_;
347327

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_;
350330

351331
Char last_char = pattern_[pattern_length - 1];
352332
size_t index = start_index;
@@ -397,8 +377,8 @@ void StringSearch<Char>::PopulateBoyerMooreTable() {
397377

398378
// Biased tables so that we can use pattern indices as table indices,
399379
// 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_;
402382

403383
// Initialize table.
404384
for (size_t i = start; i < pattern_length; i++) {
@@ -462,7 +442,7 @@ size_t StringSearch<Char>::BoyerMooreHorspoolSearch(
462442
size_t start_index) {
463443
const size_t subject_length = subject.length();
464444
const size_t pattern_length = pattern_.length();
465-
int* char_occurrences = bad_char_table();
445+
int* char_occurrences = bad_char_shift_table_;
466446
int64_t badness = -pattern_length;
467447

468448
// How bad we are doing without a good-suffix table.
@@ -511,7 +491,7 @@ template <typename Char>
511491
void StringSearch<Char>::PopulateBoyerMooreHorspoolTable() {
512492
const size_t pattern_length = pattern_.length();
513493

514-
int* bad_char_occurrence = bad_char_table();
494+
int* bad_char_occurrence = bad_char_shift_table_;
515495

516496
// Only preprocess at most kBMMaxShift last characters of pattern.
517497
const size_t start = start_;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.