This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Replace a loop with memchr
authorKarl Williamson <khw@cpan.org>
Sat, 7 Dec 2019 22:39:18 +0000 (15:39 -0700)
committerKarl Williamson <khw@cpan.org>
Sat, 7 Dec 2019 22:57:18 +0000 (15:57 -0700)
regcomp.c

index 8a6ea89..cb8e509 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -19799,15 +19799,11 @@ Perl__get_regclass_nonbitmap_data(pTHX_ const regexp *prog,
                 UV prev_cp = 0;
                 U8 count = 0;
 
-                /* Ignore everything before the first new-line */
-                while (*si_string != '\n' && remaining > 0) {
-                    si_string++;
-                    remaining--;
-                }
-                assert(remaining > 0);
-
+                /* Ignore everything before and including the first new-line */
+                si_string = (const char *) memchr(si_string, '\n', SvCUR(si));
+                assert (si_string != NULL);
                 si_string++;
-                remaining--;
+                remaining = SvPVX(si) + SvCUR(si) - si_string;
 
                 while (remaining > 0) {