Optimise more inputs to `regexp-opt' (bug#36444)

Use a more precise test to determine whether the input to `regexp-opt'
is safe to optimise when KEEP-ORDER is non-nil, permitting more inputs
to be optimised than before.  For example, ("good" "goal" "go") is now
accepted.

* lisp/emacs-lisp/regexp-opt.el (regexp-opt):
More precise test for whether the list is safe w.r.t. KEEP-ORDER.
(regexp-opt--contains-prefix): Remove.

* test/lisp/emacs-lisp/regexp-opt-tests.el: Use lexical-binding.
(regexp-opt-test--permutation, regexp-opt-test--factorial)
(regexp-opt-test--permutations, regexp-opt-test--match-all)
(regexp-opt-test--check-perm, regexp-opt-test--explain-perm)
(regexp-opt-keep-order): Test KEEP-ORDER.
1 job for master in 51 minutes and 32 seconds (queued for 1 second)
Status Job ID Name Coverage
  Test
failed #2367
test-all

00:51:32

 
Name Stage Failure
failed
test-all Test
Makefile:318: recipe for target 'check-doit' failed
make[2]: Leaving directory '/builds/emacs/emacs/test'
make[2]: *** [check-doit] Error 1
make[1]: *** [check-expensive] Error 2
Makefile:293: recipe for target 'check-expensive' failed
make[1]: Leaving directory '/builds/emacs/emacs/test'
Makefile:959: recipe for target 'check-expensive' failed
make: *** [check-expensive] Error 2
ERROR: Job failed: exit code 1