summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-12-10 11:09:51 +0000
committerDavid Mitchell <davem@iabyn.com>2011-12-19 15:06:07 +0000
commitf4fcd009302f3932f2a00257d661bd74df62d561 (patch)
tree4ef880c0982d3574343df1a7cb124f6611eb2b19
parentbeaffcddbdc0d74dd59e4e97e08d22d384e01abb (diff)
downloadperl-f4fcd009302f3932f2a00257d661bd74df62d561.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.c38
1 files 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