This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Don't interate a loop needlessly
authorKarl Williamson <khw@cpan.org>
Sat, 16 Feb 2019 18:29:51 +0000 (11:29 -0700)
committerKarl Williamson <khw@cpan.org>
Sat, 16 Feb 2019 18:31:05 +0000 (11:31 -0700)
While single stepping in gdb, I noticed that this loop kept executing,
when it need not.

regcomp.c

index fffacc6..5949b88 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -18057,9 +18057,10 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
 
             invlist_iterinit(cp_list);
             for (i = 0; i <= MAX_FOLD_FROMS; i++) {
-                if (invlist_iternext(cp_list, &start[i], &end[i])) {
-                    partial_cp_count += end[i] - start[i] + 1;
+                if (invlist_iternext(cp_list, &start[i], &end[i])) {
+                    break;
                 }
+                partial_cp_count += end[i] - start[i] + 1;
             }
 
             invlist_iterfinish(cp_list);