This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c: Replace loop by memchr()
authorKarl Williamson <khw@cpan.org>
Wed, 27 Dec 2017 01:13:36 +0000 (18:13 -0700)
committerKarl Williamson <khw@cpan.org>
Sat, 30 Dec 2017 17:41:59 +0000 (10:41 -0700)
This loop can be potentially very long as it is used to find the next
place there is a potential match in something like /(foo)+abc/.  (It's
trying to find the 'a' in that example.

regexec.c

index 98421e1..5c9d7b6 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -8653,9 +8653,12 @@ NULL
                }
                else {  /* Not utf8_target */
                    if (ST.c1 == ST.c2) {
-                       while (locinput <= ST.maxpos &&
-                              UCHARAT(locinput) != ST.c1)
-                           locinput++;
+                        locinput = (char *) memchr(locinput,
+                                                   ST.c1,
+                                                   ST.maxpos + 1 - locinput);
+                        if (! locinput) {
+                            locinput = ST.maxpos + 1;
+                        }
                    }
                     else {
                         U8 c1_c2_bits_differing = ST.c1 ^ ST.c2;