From f4fcd009302f3932f2a00257d661bd74df62d561 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Sat, 10 Dec 2011 11:09:51 +0000 Subject: 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 --- regcomp.c | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/regcomp.c b/regcomp.c index 6d4ebe4645..f0b9a29397 100644 --- a/regcomp.c +++ b/regcomp.c @@ -4852,16 +4852,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; @@ -4948,22 +4938,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 -- cgit v1.2.1