This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re_op_compile(): merge the two 'eq old_re' checks
authorDavid Mitchell <davem@iabyn.com>
Sat, 10 Dec 2011 11:09:51 +0000 (11:09 +0000)
committerDavid Mitchell <davem@iabyn.com>
Wed, 13 Jun 2012 12:32:47 +0000 (13:32 +0100)
The code had two similar checks for whether the new pattern was the same
as the old (and so skip recompilation); the second was for after a longjmp
and upgrade to UTF8. By moving both checks to just after the
"if (jump_ret == 0)" block we should achieve code simplification without
any change in functionality

regcomp.c

index 17fb4e0..289308c 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -5333,16 +5333,6 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
        return CALLREGCOMP_ENG(eng, pat, orig_rx_flags);
     }
 
-    if (   old_re
-       && !!RX_UTF8(old_re) == !!SvUTF8(pat)
-       && RX_PRECOMP(old_re) && RX_PRELEN(old_re) == plen
-       && memEQ(RX_PRECOMP(old_re), exp, plen))
-    {
-       ReREFCNT_inc(old_re);
-       Safefree(pRExC_state->code_blocks);
-       return old_re;
-    }
-
     /* ignore the utf8ness if the pattern is 0 length */
     RExC_utf8 = RExC_orig_utf8 = (plen == 0 || IN_BYTES) ? 0 : SvUTF8(pat);
     RExC_uni_semantics = 0;
@@ -5429,22 +5419,22 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
        xend = exp + plen;
        SAVEFREEPV(exp);
        RExC_orig_utf8 = RExC_utf8 = 1;
+    }
 
-       /* we've changed the string; check again whether it matches
-        * the old pattern, to avoid recompilation */
-       if (   old_re
-           && RX_UTF8(old_re)
-           && RX_PRECOMP(old_re) && RX_PRELEN(old_re) == plen
-           && memEQ(RX_PRECOMP(old_re), exp, plen))
-       {
-           ReREFCNT_inc(old_re);
-           if (used_setjump) {
-               JMPENV_POP;
-           }
-           Safefree(pRExC_state->code_blocks);
-           return old_re;
-       }
+    /* return old regex if pattern hasn't changed */
 
+    if (   old_re
+       && !!RX_UTF8(old_re) == !!RExC_utf8
+       && RX_PRECOMP(old_re)
+       && RX_PRELEN(old_re) == plen
+       && memEQ(RX_PRECOMP(old_re), exp, plen))
+    {
+       ReREFCNT_inc(old_re);
+       if (used_setjump) {
+           JMPENV_POP;
+       }
+       Safefree(pRExC_state->code_blocks);
+       return old_re;
     }
 
 #ifdef TRIE_STUDY_OPT