Skip to content

Commit

Permalink
Don't let DFA execution bail when slow for RE2::Set.
Browse files Browse the repository at this point in the history
Change-Id: I0e6b8c32cc78a4d37ecf241f2c42c3d2303f388d
Reviewed-on: https://code-review.googlesource.com/c/re2/+/42012
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
junyer committed Jun 14, 2019
1 parent d067bdd commit 848dfb7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
6 changes: 4 additions & 2 deletions re2/dfa.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,11 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params,
// byte runs at about 0.2 MB/s, while the NFA (nfa.cc) can do the
// same at about 2 MB/s. Unless we're processing an average
// of 10 bytes per state computation, fail so that RE2 can
// fall back to the NFA.
// fall back to the NFA. However, RE2::Set cannot fall back,
// so we just have to keep on keeping on in that case.
if (dfa_should_bail_when_slow && resetp != NULL &&
static_cast<size_t>(p - resetp) < 10*state_cache_.size()) {
static_cast<size_t>(p - resetp) < 10*state_cache_.size() &&
kind_ != Prog::kManyMatch) {
params->failed = true;
return false;
}
Expand Down
14 changes: 0 additions & 14 deletions re2/testing/set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,4 @@ TEST(Set, Prefix) {
ASSERT_EQ(v[0], 0);
}

TEST(Set, OutOfMemory) {
RE2::Set s(RE2::DefaultOptions, RE2::UNANCHORED);

std::string a(10000, 'a');
ASSERT_EQ(s.Add(a, NULL), 0);
ASSERT_EQ(s.Compile(), true);

std::vector<int> v;
RE2::Set::ErrorInfo ei;
ASSERT_EQ(s.Match(a, &v, &ei), false);
ASSERT_EQ(v.size(), 0);
ASSERT_EQ(ei.kind, RE2::Set::kOutOfMemory);
}

} // namespace re2

0 comments on commit 848dfb7

Please sign in to comment.