Commit c8e4c8b9 authored by jgruber's avatar jgruber Committed by Commit bot

[regexp] Fold repeated assertions

For instance, /\b\b\b\B\B\B/ is folded into the equivalent /\b\B/.

BUG=v8:6126

Review-Url: https://codereview.chromium.org/2768443003
Cr-Commit-Position: refs/heads/master@{#44004}
parent da511d33
......@@ -1691,6 +1691,12 @@ void RegExpBuilder::AddTerm(RegExpTree* term) {
void RegExpBuilder::AddAssertion(RegExpTree* assert) {
FlushText();
if (terms_.length() > 0 && terms_.last()->IsAssertion()) {
// Omit repeated assertions of the same type.
RegExpAssertion* last = terms_.last()->AsAssertion();
RegExpAssertion* next = assert->AsAssertion();
if (last->assertion_type() == next->assertion_type()) return;
}
terms_.Add(assert, zone());
LAST(ADD_ASSERT);
}
......
......@@ -314,6 +314,9 @@ void TestRegExpParser(bool lookbehind) {
CheckParseEq("\\u0034", "'\x34'");
CheckParseEq("\\u003z", "'u003z'");
CheckParseEq("foo[z]*", "(: 'foo' (# 0 - g [z]))");
CheckParseEq("^^^$$$\\b\\b\\b\\b", "(: @^i @$i @b)");
CheckParseEq("\\b\\b\\b\\b\\B\\B\\B\\B\\b\\b\\b\\b", "(: @b @B @b)");
CheckParseEq("\\b\\B\\b", "(: @b @B @b)");
// Unicode regexps
CheckParseEq("\\u{12345}", "'\\ud808\\udf45'", true);
......
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