Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix -Wmaybe-uninitialized compiler warning #31809

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "req_wrap-inl.h"
#include "stream_base-inl.h"
#include "string_bytes.h"
#include "string_search.h"

#include <fcntl.h>
#include <sys/types.h>
Expand Down
35 changes: 27 additions & 8 deletions src/string_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,29 @@ class StringSearch : private StringSearchBase {
CHECK_GT(pattern_length, 0);
if (pattern_length < kBMMinPatternLength) {
if (pattern_length == 1) {
strategy_ = &StringSearch::SingleCharSearch;
strategy_ = SearchStrategy::kSingleChar;
return;
}
strategy_ = &StringSearch::LinearSearch;
strategy_ = SearchStrategy::kLinear;
return;
}
strategy_ = &StringSearch::InitialSearch;
strategy_ = SearchStrategy::kInitial;
}

size_t Search(Vector subject, size_t index) {
return (this->*strategy_)(subject, index);
switch (strategy_) {
case kBoyerMooreHorspool:
return BoyerMooreHorspoolSearch(subject, index);
case kBoyerMoore:
return BoyerMooreSearch(subject, index);
case kInitial:
return InitialSearch(subject, index);
case kLinear:
return LinearSearch(subject, index);
case kSingleChar:
return SingleCharSearch(subject, index);
}
UNREACHABLE();
}

static inline int AlphabetSize() {
Expand Down Expand Up @@ -149,10 +161,17 @@ class StringSearch : private StringSearchBase {
return bad_char_occurrence[equiv_class];
}

enum SearchStrategy {
kBoyerMooreHorspool,
kBoyerMoore,
kInitial,
kLinear,
kSingleChar,
};

// The pattern to search for.
Vector pattern_;
// Pointer to implementation of the search.
SearchFunction strategy_;
SearchStrategy strategy_;
// Cache value of Max(0, pattern_length() - kBMMaxShift)
size_t start_;
};
Expand Down Expand Up @@ -476,7 +495,7 @@ size_t StringSearch<Char>::BoyerMooreHorspoolSearch(
badness += (pattern_length - j) - last_char_shift;
if (badness > 0) {
PopulateBoyerMooreTable();
strategy_ = &StringSearch::BoyerMooreSearch;
strategy_ = SearchStrategy::kBoyerMoore;
return BoyerMooreSearch(subject, index);
}
}
Expand Down Expand Up @@ -548,7 +567,7 @@ size_t StringSearch<Char>::InitialSearch(
badness += j;
} else {
PopulateBoyerMooreHorspoolTable();
strategy_ = &StringSearch::BoyerMooreHorspoolSearch;
strategy_ = SearchStrategy::kBoyerMooreHorspool;
return BoyerMooreHorspoolSearch(subject, i);
}
}
Expand Down