summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-02-17 14:17:13 +0000
committerDavid Mitchell <davem@iabyn.com>2011-02-18 11:25:24 +0000
commit5e79dfb9cd4496df40e823bec270c4bcde98db07 (patch)
tree953903923b74c8cf59bdb9cb6154775863c013fd /pp_hot.c
parent0ab462a656aa799cb05352f5ff7596c9bf6893ee (diff)
downloadperl-5e79dfb9cd4496df40e823bec270c4bcde98db07.tar.gz
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)
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 8fb2f61be4..4fb5f01aab 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