From 5e79dfb9cd4496df40e823bec270c4bcde98db07 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Thu, 17 Feb 2011 14:17:13 +0000 Subject: [PATCH] pp_subst: exit earlier after failed match If the match fails, don't bother to execute some code that prepares the source and replacement strings for a substitution (e.g. matching UTF8-ness). (This is an enhancement to ff6e92e827a143094fdf3af374056b524759194b) --- pp_hot.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 8fb2f61..4fb5f01 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -2252,6 +2252,15 @@ PP(pp_subst) matched = CALLREGEXEC(rx, s, strend, orig, 0, TARG, NULL, r_flags | REXEC_CHECKED); + + if (!matched) { + ret_no: + SPAGAIN; + PUSHs(rpm->op_pmflags & PMf_NONDESTRUCT ? TARG : &PL_sv_no); + LEAVE_SCOPE(oldsave); + RETURN; + } + /* known replacement string? */ if (dstr) { if (SvTAINTED(dstr)) @@ -2261,7 +2270,7 @@ PP(pp_subst) * but only if it matched; see * http://www.nntp.perl.org/group/perl.perl5.porters/2010/04/msg158809.html */ - if (matched && DO_UTF8(dstr) && ! DO_UTF8(TARG)) { + if (DO_UTF8(dstr) && ! DO_UTF8(TARG)) { char * const orig_pvx = SvPVX(TARG); const STRLEN new_len = sv_utf8_upgrade_nomg(TARG); @@ -2294,14 +2303,6 @@ PP(pp_subst) doutf8 = FALSE; } - if (!matched) { - ret_no: - SPAGAIN; - PUSHs(rpm->op_pmflags & PMf_NONDESTRUCT ? TARG : &PL_sv_no); - LEAVE_SCOPE(oldsave); - RETURN; - } - /* can do inplace substitution? */ if (c #ifdef PERL_OLD_COPY_ON_WRITE -- 2.7.4