Skip to content

test: fix RegExp nits

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

test

It will be easier to review this PR commit by commit, performance-wise and for better comprehending (different changes are confusingly interwoven in the overall diff).

  1. Remove redundant RegExp part.

    RegExp part with a quantifier '0 or more times' is redundant if it is used at the very edge of the RegExp and is not captured or does not affect match indices (UPD: and should not greedily take up previous similar parts).

  2. Remove needless RegExp flag.

    In fixed case, /g flag is needless in the boolean context.

  3. Remove needless RegExp capturing.

    Use non-capturing grouping or remove capturing completely when:

    • capturing is useless per se, e.g. in test() check;
    • captured groups are not used afterward at all;
    • some of the later captured groups are not used afterward.

  4. Use test(), not match() or exec() in boolean context.

    match() and exec() return a complicated object, unneeded in a boolean context. This fix also makes the code more clear and predictable.

  5. Do not needlessly repeat RegExp creation.

    This is the largest commit, however, it is rather easy to skim. It takes RegExp creation out of cycles and other repetitions.

    As long as the RegExp does not use /g flag + match indices, we are safe here.

    In tests, this fix hardly gives a significant performance gain, but it increases clarity and maintainability, reassuring some RegExps to be identical.

    RegExps in functions are not taken out of their functions: while these functions are called many times and their RegExps are recreated with each call, the performance gain in test cases does not seem to be worth decreasing function self-dependency.

Merge request reports

Loading