Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a458a6c1f0a71390a7641f8fbb5a5485c6900a1e
      
https://github.com/WebKit/WebKit/commit/a458a6c1f0a71390a7641f8fbb5a5485c6900a1e
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-08-01 (Sat, 01 Aug 2026)

  Changed paths:
    M Source/JavaScriptCore/yarr/YarrPattern.cpp

  Log Message:
  -----------
  [YARR] Stop the chunked v-mode class set operation loop as soon as it can 
produce nothing more
https://bugs.webkit.org/show_bug.cgi?id=320619

Reviewed by Yusuke Suzuki.

CharacterClassConstructor::nonLatin1OpSorted() computes v-mode class set
operations over the non-Latin-1 range by walking 0x100..0x10FFFF in
2048-codepoint chunks until every LHS/RHS index is consumed. It had an
early-exit for intersection with an exhausted RHS, but that compared
rhsRangeIndex with '>' against rhsRanges32.size(), which can never be true,
so /[\p{Any}&&[a-c]]/v scanned all ~540 chunks even though the RHS has no
non-Latin-1 elements at all.

Replace the loop condition with an op-aware canProduceMore() predicate:
union continues while either side has input left, intersection while both
do, and subtraction while the LHS does. This subsumes the dead early-exit and
the empty-input bail-out, and additionally stops early when the LHS of an
intersection or a subtraction is exhausted. The resulting character sets are
unchanged.

Microbenchmark (500 constructions of new RegExp("(?:x" + i + ")?" + pattern, 
"v")):

    pattern                        baseline      patched

    [\p{Any}&&[a-c]]                1876.6 ms       2.9 ms
    [[a-c]&&\p{Any}]                1866.6 ms       2.3 ms
    [\p{L}&&\p{Any}]                2458.2 ms     981.7 ms
    [\p{Any}--[a-c]]                4862.2 ms    4932.5 ms
    [[\u{100}-\u{200}]--\p{Any}]    1774.9 ms       6.8 ms
    [\p{L}[0-9]]                     645.5 ms     696.4 ms

* Source/JavaScriptCore/yarr/YarrPattern.cpp:
(JSC::Yarr::CharacterClassConstructor::nonLatin1OpSorted):

Canonical link: https://commits.webkit.org/318392@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to