Skip to content

Commit 8df7c2a

Browse files
ErikCorryGoogleCommit bot
authored and
Commit bot
committed
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 atom/find-and-replace#571 [email protected] BUG= Review-Url: https://codereview.chromium.org/2777583003 Cr-Commit-Position: refs/heads/master@{#44139}
1 parent cb31746 commit 8df7c2a

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/regexp/jsregexp.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -2302,9 +2302,7 @@ int ActionNode::EatsAtLeast(int still_to_find,
23022302

23032303
void ActionNode::FillInBMInfo(Isolate* isolate, int offset, int budget,
23042304
BoyerMooreLookahead* bm, bool not_at_start) {
2305-
if (action_type_ == BEGIN_SUBMATCH) {
2306-
bm->SetRest(offset);
2307-
} else if (action_type_ != POSITIVE_SUBMATCH_SUCCESS) {
2305+
if (action_type_ != POSITIVE_SUBMATCH_SUCCESS) {
23082306
on_success()->FillInBMInfo(isolate, offset, budget - 1, bm, not_at_start);
23092307
}
23102308
SaveBMInfo(bm, not_at_start, offset);

0 commit comments

Comments
 (0)