| Index: src/parser.cc
|
| ===================================================================
|
| --- src/parser.cc (revision 1004)
|
| +++ src/parser.cc (working copy)
|
| @@ -527,7 +527,9 @@
|
| void Advance(int dist);
|
| void Reset(int pos);
|
|
|
| - bool HasCharacterEscapes();
|
| + // Reports whether the pattern might be used as a literal search string.
|
| + // Only use if the result of the parse is a single atom node.
|
| + bool simple();
|
|
|
| int captures_started() { return captures_ == NULL ? 0 : captures_->length(); }
|
| int position() { return next_pos_ - 1; }
|
| @@ -548,7 +550,7 @@
|
| int next_pos_;
|
| FlatStringReader* in_;
|
| Handle<String>* error_;
|
| - bool has_character_escapes_;
|
| + bool simple_;
|
| ZoneList<RegExpCapture*>* captures_;
|
| bool is_scanned_for_captures_;
|
| // The capture count is only valid after we have scanned for captures.
|
| @@ -3501,7 +3503,7 @@
|
| next_pos_(0),
|
| in_(in),
|
| error_(error),
|
| - has_character_escapes_(false),
|
| + simple_(true),
|
| captures_(NULL),
|
| is_scanned_for_captures_(false),
|
| capture_count_(0),
|
| @@ -3549,11 +3551,8 @@
|
| }
|
|
|
|
|
| -// Reports whether the parsed string atoms contain any characters that were
|
| -// escaped in the original pattern. If not, all atoms are proper substrings
|
| -// of the original pattern.
|
| -bool RegExpParser::HasCharacterEscapes() {
|
| - return has_character_escapes_;
|
| +bool RegExpParser::simple() {
|
| + return simple_;
|
| }
|
|
|
| RegExpTree* RegExpParser::ReportError(Vector<const char> message) {
|
| @@ -3768,7 +3767,7 @@
|
| Advance(2);
|
| break;
|
| }
|
| - has_character_escapes_ = true;
|
| + simple_ = false;
|
| break;
|
| case '{': {
|
| int dummy;
|
| @@ -3821,6 +3820,7 @@
|
| is_greedy = false;
|
| Advance();
|
| }
|
| + simple_ = false; // Adding quantifier might *remove* look-ahead.
|
| builder.AddQuantifierToAtom(min, max, is_greedy);
|
| }
|
| }
|
| @@ -4301,20 +4301,22 @@
|
|
|
| bool ParseRegExp(FlatStringReader* input,
|
| bool multiline,
|
| - RegExpParseResult* result) {
|
| + RegExpCompileData* result) {
|
| ASSERT(result != NULL);
|
| // Make sure we have a stack guard.
|
| StackGuard guard;
|
| RegExpParser parser(input, &result->error, multiline);
|
| - result->tree = parser.ParsePattern();
|
| + RegExpTree* tree = parser.ParsePattern();
|
| if (parser.failed()) {
|
| - ASSERT(result->tree == NULL);
|
| + ASSERT(tree == NULL);
|
| ASSERT(!result->error.is_null());
|
| } else {
|
| - ASSERT(result->tree != NULL);
|
| + ASSERT(tree != NULL);
|
| ASSERT(result->error.is_null());
|
| - result->has_character_escapes = parser.HasCharacterEscapes();
|
| - result->capture_count = parser.captures_started();
|
| + result->tree = tree;
|
| + int capture_count = parser.captures_started();
|
| + result->simple = tree->IsAtom() && parser.simple() && capture_count == 0;
|
| + result->capture_count = capture_count;
|
| }
|
| return !parser.failed();
|
| }
|
|
|