Index: src/jsregexp.cc |
diff --git a/src/jsregexp.cc b/src/jsregexp.cc |
index 82a370f141fecf845cb4bd08ec3fdd390cc1f519..3c5ddfbeb4ffd0ed4dbb3fb53ef9fd5317d5f2ce 100644 |
--- a/src/jsregexp.cc |
+++ b/src/jsregexp.cc |
@@ -5180,7 +5180,10 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(RegExpCompileData* data, |
&compiler, |
compiler.accept()); |
RegExpNode* node = captured_body; |
- if (!data->tree->IsAnchored()) { |
+ bool is_end_anchored = data->tree->IsAnchoredAtEnd(); |
+ bool is_start_anchored = data->tree->IsAnchoredAtStart(); |
+ int max_length = data->tree->max_match(); |
+ if (!is_start_anchored) { |
// Add a .*? at the beginning, outside the body capture, unless |
// this expression is anchored at the beginning. |
RegExpNode* loop_node = |
@@ -5236,6 +5239,15 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(RegExpCompileData* data, |
RegExpMacroAssemblerIrregexp macro_assembler(codes); |
#endif // V8_INTERPRETED_REGEXP |
+ // Inserted here, instead of in Assembler, because it depends on information |
+ // in the AST that isn't replicated in the Node structure. |
+ static const int kMaxBacksearchLimit = 1024; |
+ if (is_end_anchored && |
+ !is_start_anchored && |
+ max_length < kMaxBacksearchLimit) { |
+ macro_assembler.SetCurrentPositionFromEnd(max_length); |
+ } |
+ |
return compiler.Assemble(¯o_assembler, |
node, |
data->capture_count, |