This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c: Combine adjacent 'ifs' with same clause
authorKarl Williamson <public@khwilliamson.com>
Wed, 19 Dec 2012 20:54:16 +0000 (13:54 -0700)
committerKarl Williamson <public@khwilliamson.com>
Sat, 22 Dec 2012 18:11:33 +0000 (11:11 -0700)
These two instances of 'if (a) { b } if (c) { b }  are combined to
    if (a || c) { b }

The final instance is made into an else since the 'if' before it does a
break, so that the break is eliminated.

regexec.c

index e4dc386..b265048 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -4066,9 +4066,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                      * is an invariant, but there are tests in the test suite
                      * dealing with (??{...}) which violate this) */
                    while (s < e) {
-                       if (l >= PL_regeol)
-                            sayNO;
-                        if (UTF8_IS_ABOVE_LATIN1(* (U8*) l)) {
+                       if (l >= PL_regeol || UTF8_IS_ABOVE_LATIN1(* (U8*) l)) {
                             sayNO;
                         }
                         if (UTF8_IS_INVARIANT(*(U8*)l)) {
@@ -4109,17 +4107,18 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                    }
                }
                locinput = l;
-               break;
            }
-           /* The target and the pattern have the same utf8ness. */
-           /* Inline the first character, for speed. */
-           if (UCHARAT(s) != nextchr)
-               sayNO;
-           if (PL_regeol - locinput < ln)
-               sayNO;
-           if (ln > 1 && memNE(s, locinput, ln))
-               sayNO;
-           locinput += ln;
+            else {
+                /* The target and the pattern have the same utf8ness. */
+                /* Inline the first character, for speed. */
+                if (PL_regeol - locinput < ln
+                    || UCHARAT(s) != nextchr
+                    || (ln > 1 && memNE(s, locinput, ln)))
+                {
+                    sayNO;
+                }
+                locinput += ln;
+            }
            break;
            }