Commit 8df7c2a2 authored by erikcorry's avatar erikcorry Committed by Commit bot

Regexp: Optimize better in presence of lookaround.

Previously the Boyer-Moore-Horspool optimization gave up in the presence of a
submatch.  A submatch is where we record the current position so that we can go
back to it, which is an essential part of the semantics of lookarounds
(lookaheads and lookbehinds).  This has been the case since
Boyer-Moore-Horspool was implemented, but it was overly cautious.

* For positive lookahead it is OK to use the patterns inside the lookahead to
  guide the BMS optimization.
* For positive lookbehind we harmlessly fail to optimize when the patterns
  inside the lookbehind go backwards because TextNode::EatsAtLeast returns 0.
* For negative lookarounds, the NegativeLookaroundChoiceNode::FillInBMInfo method
  (in jsregexp.h) knows to only look at the following pattern.

This is in response to disappointing lookbehind performance in Atom.
See https://github.com/atom/find-and-replace/issues/571

R=yangguo@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2777583003
Cr-Commit-Position: refs/heads/master@{#44139}
parent cb317463
......@@ -2302,9 +2302,7 @@ int ActionNode::EatsAtLeast(int still_to_find,
void ActionNode::FillInBMInfo(Isolate* isolate, int offset, int budget,
BoyerMooreLookahead* bm, bool not_at_start) {
if (action_type_ == BEGIN_SUBMATCH) {
bm->SetRest(offset);
} else if (action_type_ != POSITIVE_SUBMATCH_SUCCESS) {
if (action_type_ != POSITIVE_SUBMATCH_SUCCESS) {
on_success()->FillInBMInfo(isolate, offset, budget - 1, bm, not_at_start);
}
SaveBMInfo(bm, not_at_start, offset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment