Chromium Code Reviews| Index: regexp2000/src/parser.cc |
| diff --git a/regexp2000/src/parser.cc b/regexp2000/src/parser.cc |
| index 33d34aa686348aba0d343f339900182ff7e3f0e0..c3d21161158e2237d3336776033b40f7ea8a4c79 100644 |
| --- a/regexp2000/src/parser.cc |
| +++ b/regexp2000/src/parser.cc |
| @@ -387,6 +387,10 @@ void RegExpBuilder::AddEmpty() { |
| void RegExpBuilder::AddAtom(RegExpTree* term) { |
| + if (term->IsEmpty()) { |
| + AddEmpty(); |
| + return; |
| + } |
| if (term->IsTextElement()) { |
| FlushCharacters(); |
| text_.Add(term); |
| @@ -470,6 +474,16 @@ void RegExpBuilder::AddQuantifierToAtom(int min, int max, bool is_greedy) { |
| } else if (terms_.length() > 0) { |
| ASSERT(last_added_ == ADD_ATOM); |
| atom = terms_.RemoveLast(); |
| + if (atom->IsLookahead() || atom->IsAssertion()) { |
|
Christian Plesner Hansen
2008/11/17 10:54:35
I wonder if this is worthwhile?
Lasse Reichstein
2008/11/17 11:26:32
It probably isn't. It's optimizing the case where
|
| + // Guaranteed not to match a non-empty string. |
| + // Assertion as an atom can happen as, e.g., (?:\b) |
| + LAST(ADD_TERM); |
| + if (min == 0) { |
| + return; |
| + } |
| + terms_.Add(atom); |
| + return; |
| + } |
| } else { |
| // Only call immediately after adding an atom or character! |
| UNREACHABLE(); |