libs: fix some RegExp nits
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
commit message follows commit guidelines
Affected core subsystem(s)
cluster, dns, repl, tls, util
-
Take
RegExp
creation out of cycles.I am not sure if v8 fully optimizes this now (= makes some
RegExp
s an identical one in cycles), so I've addressed this to be on the safe side. As long as theRegExp
does not useg
flag and match indices, we are safe here. -
Use
test()
, notmatch()
in boolean context.match()
returns a complicated object, unneeded in a boolean context. -
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.