From fbfb1899dd79253696b441cc1c4968a1057c2574 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Sat, 1 Sep 2012 11:23:58 +0100 Subject: [PATCH] tidy up patten match copying code (no functional changes). 1. Remove some dead code from pp_split; it's protected by an assert that it could never be called. 2. Simplify the flags settings for the call to CALLREGEXEC() in pp_substcont: on subsequent matches we always set REXEC_NOT_FIRST, which forces the regex engine not to copy anyway, so passing the REXEC_COPY_STR is pointless, as is the conditional code to set it. 3. (whitespace change): split a conditional expression over 2 lines for easier reading. --- pp.c | 7 ------- pp_ctl.c | 4 +--- pp_hot.c | 3 ++- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/pp.c b/pp.c index 1c7b18a..e1a6c78 100644 --- a/pp.c +++ b/pp.c @@ -5552,13 +5552,6 @@ PP(pp_split) /* we never pass the REXEC_COPY_STR flag, so it should * never get copied */ assert(!RX_MATCH_COPIED(rx)); - if (RX_MATCH_COPIED(rx) && RX_SUBBEG(rx) != orig) { - m = s; - s = orig; - orig = RX_SUBBEG(rx); - s = orig + (m - s); - strend = s + (strend - m); - } m = RX_OFFS(rx)[0].start + orig; if (gimme_scalar) { diff --git a/pp_ctl.c b/pp_ctl.c index ecb8c9f..af0d558 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -216,9 +216,7 @@ PP(pp_substcont) if (CxONCE(cx) || s < orig || !CALLREGEXEC(rx, s, cx->sb_strend, orig, (s == m) + RX_GOFS(rx), cx->sb_targ, NULL, - ((cx->sb_rflags & REXEC_COPY_STR) - ? (REXEC_IGNOREPOS|REXEC_NOT_FIRST) - : (REXEC_COPY_STR|REXEC_IGNOREPOS|REXEC_NOT_FIRST)))) + (REXEC_IGNOREPOS|REXEC_NOT_FIRST))) { SV *targ = cx->sb_targ; diff --git a/pp_hot.c b/pp_hot.c index 6530ae5..b549d1c 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2217,7 +2217,8 @@ PP(pp_subst) #ifdef PERL_OLD_COPY_ON_WRITE && !is_cow #endif - && (I32)clen <= RX_MINLENRET(rx) && (once || !(r_flags & REXEC_COPY_STR)) + && (I32)clen <= RX_MINLENRET(rx) + && (once || !(r_flags & REXEC_COPY_STR)) && !(RX_EXTFLAGS(rx) & RXf_LOOKBEHIND_SEEN) && (!doutf8 || SvUTF8(TARG)) && !(rpm->op_pmflags & PMf_NONDESTRUCT)) -- 2.7.4