Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JSC] Extend BoyerMoore search more
https://bugs.webkit.org/show_bug.cgi?id=251903
rdar://105160925

Reviewed by Michael Saboff.

This patch further extends BoyerMoore search coverage to unlock this in various regular expressions.
In particular, this supports nested disjunctions, like, /aaa|(bbb|cccc)/ can be supported now.
This patch improves JetStream2/regexp by 12%.

* Source/JavaScriptCore/yarr/YarrJIT.cpp:

Canonical link: https://commits.webkit.org/260054@main
  • Loading branch information
Constellation committed Feb 9, 2023
1 parent 52f0003 commit bb136cc
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 78 deletions.
90 changes: 90 additions & 0 deletions JSTests/stress/boyer-moore-filter.js
@@ -0,0 +1,90 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}

{
let regexp = /aaaa|(bbb|cccc)/; // => [abc][abc][abc]
shouldBe(regexp.test("bbb"), true);
shouldBe(regexp.test("aabb"), false);
}

{
let regexp = /aaaa|(bbb|cccc)?/; // =>
shouldBe(regexp.test("bbb"), true);
shouldBe(regexp.test("aabb"), true);
shouldBe(regexp.test(""), true);
}

{
let regexp = /aaaa|a(bbb|cccc)?/; // => [a]
shouldBe(regexp.test("aaaa"), true);
shouldBe(regexp.test("a"), true);
shouldBe(regexp.test("abbb"), true);
shouldBe(regexp.test("acccc"), true);
shouldBe(regexp.test("dcccc"), false);
}

{
let regexp = /aaaa|(bbb|cccc)?dd/; // => [abcd]
shouldBe(regexp.test("bbb"), false);
shouldBe(regexp.test("aaaa"), true);
shouldBe(regexp.test("aabb"), false);
shouldBe(regexp.test("dd"), true);
}

{
let regexp = /aaaa|(bbb|cccc?)?dd/; // => [abc][abc][abc]
shouldBe(regexp.test("bbb"), false);
shouldBe(regexp.test("aaaa"), true);
shouldBe(regexp.test("aabb"), false);
shouldBe(regexp.test("dd"), true);
}

{
let regexp = /aaaa|(b|cccc)dd/; // => [abc][acd]
shouldBe(regexp.test("bbb"), false);
shouldBe(regexp.test("aaaa"), true);
shouldBe(regexp.test("aabb"), false);
shouldBe(regexp.test("ccccdd"), true);
shouldBe(regexp.test("ccccdd"), true);
}

{
let regexp = /aaaaaaa|(bb?|cc?)dddddd/; // => [abc][acd]
shouldBe(regexp.test("aaaaaaa"), true);
shouldBe(regexp.test("bdddddd"), true);
shouldBe(regexp.test("cdddddd"), true);
shouldBe(regexp.test("bbdddddd"), true);
shouldBe(regexp.test("ccdddddd"), true);
shouldBe(regexp.test("dddddd"), false);
shouldBe(regexp.test("dddddd"), false);
shouldBe(regexp.test("bddddd"), false);
shouldBe(regexp.test("cddddd"), false);
shouldBe(regexp.test("bbddddd"), false);
shouldBe(regexp.test("ccddddd"), false);
shouldBe(regexp.test("aaaaaabdddddd"), true);
shouldBe(regexp.test("aaaaaacdddddd"), true);
shouldBe(regexp.test("aaaaaabbdddddd"), true);
shouldBe(regexp.test("aaaaaaccdddddd"), true);
}

{
let regexp = /\baaaaaaa|(bb?|cc?)dddddd/; // => [abc][acd]
shouldBe(regexp.test("aaaaaaa"), true);
shouldBe(regexp.test("bdddddd"), true);
shouldBe(regexp.test("cdddddd"), true);
shouldBe(regexp.test("bbdddddd"), true);
shouldBe(regexp.test("ccdddddd"), true);
shouldBe(regexp.test("dddddd"), false);
shouldBe(regexp.test("dddddd"), false);
shouldBe(regexp.test("bddddd"), false);
shouldBe(regexp.test("cddddd"), false);
shouldBe(regexp.test("bbddddd"), false);
shouldBe(regexp.test("ccddddd"), false);
shouldBe(regexp.test("baaaaaaa"), false);
shouldBe(regexp.test("aaaaaabdddddd"), true);
shouldBe(regexp.test("aaaaaacdddddd"), true);
shouldBe(regexp.test("aaaaaabbdddddd"), true);
shouldBe(regexp.test("aaaaaaccdddddd"), true);
}

0 comments on commit bb136cc

Please sign in to comment.