diff options
author | David Mitchell <davem@iabyn.com> | 2011-12-10 11:09:51 +0000 |
---|---|---|
committer | David Mitchell <davem@iabyn.com> | 2012-06-13 13:32:47 +0100 |
commit | 3b16d10d72cd916e1907c4161cc52322040c227a (patch) | |
tree | 5162ead1d82f8ae862312cc166a3cdbcd1ac1359 | |
parent | fdfac248b2fc50e69d93d95b69996b68cebdd0f4 (diff) | |
download | perl-3b16d10d72cd916e1907c4161cc52322040c227a.tar.gz |
re_op_compile(): merge the two 'eq old_re' checks
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
-rw-r--r-- | regcomp.c | 38 |
1 files changed, 14 insertions, 24 deletions
@@ -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 |