I said this before, though I couldn't find it right off.
Here's my idea:
Change re.test(str)
to return re.exec(str) != null
, so it delegates to exec
like all the default symbol methods do. Turns out I misread the spec.
- Deprecate and maybe remove all the regexp symbols.
Well-formed RegExp shbclasses have to implement exec
anyways, so might as well save them the work of also implementing test
unless they want a perf optimization. Also, duck-typed regexp-compatible classes would benefit a lot from being able to just implement one method to rule them all.
test
already does what you said.
Not sure why, but all regexp symbols already rely on exec
. They mostly just test for flags or change lastIndex
.
They do. I was more just thinking they could just do the algorithms directly.
There really isn't any extra efficiency to gain to my knowledge to not just do it in String#split
and so on. Especially if RegExp.prototype.exec alternative that doesn't allocate a new object on every execution gets added.
Any existing, observable behavior is not to be changed, but if engines can prove optimizations to not be observable, they can do it nonetheless. For example, although the spec specifies test
in terms of exec
, in my past benchmarks I've actually found test
to be faster than exec
.