Skip to content

libs: fix some RegExp nits

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

cluster, dns, repl, tls, util

  1. Take RegExp creation out of cycles.

    I am not sure if v8 fully optimizes this now (= makes some RegExps an identical one in cycles), so I've addressed this to be on the safe side. As long as the RegExp does not use g flag and match indices, we are safe here.

  2. Use test(), not match() in boolean context.

    match() returns a complicated object, unneeded in a boolean context.

  3. Remove redundant RegExp parts.

    If I get this correctly, a RegExp part with a quantifier '0 or more' is redundant if:

    • it is used at the very beginning or the very end of the RegExp;
    • it is used in a boolean context (test());
    • or it is not captured in match()/exec() results (full or partial) or does not affect match indices.

    However, these parts may improve readability and comprehensibility. If this is the case for the changed fragments, feel free to reject the change.

These are rather trivial changes to cause any regressions, and I've tried not to cause any accidental deopts (being consistent with var / const environment style in creating variables). If anybody believes some benchmarks are needed, please, tell me which of them I should run.

It is easier to review this PR commit by commit, as the changes are interwoven and this may be confusing.

Merge request reports

Loading