Skip to content
Open
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
9 changes: 8 additions & 1 deletion re2/prefilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ void Prefilter::SimplifyStringSet(SSet* ss) {

Prefilter* Prefilter::OrStrings(SSet* ss) {
Prefilter* or_prefilter = new Prefilter(NONE);
SimplifyStringSet(ss);
// SimplifyStringSet() compares every string against every longer
// string, so it is quadratic in the size of the set. Above this
// size, skip it: it only removes redundant atoms, which is purely
// an optimisation, and keeping the redundant atoms is always
// correct, because the prefilter only has to be a necessary
// condition for a match.
if (ss->size() <= 4096)
SimplifyStringSet(ss);
for (SSIter i = ss->begin(); i != ss->end(); ++i)
or_prefilter = Or(or_prefilter, FromString(*i));
return or_prefilter;
Expand Down