summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2010-07-03 13:17:40 +0100
committerDavid Mitchell <davem@iabyn.com>2010-07-03 16:25:58 +0100
commitf3ec07c74992f83551f19ac514b0c40fd1e93787 (patch)
tree284e8b12cd7a8514ae42761badfb30af4dbe360c /pp_ctl.c
parent3bc4ee4c5aa3ed1ba3b33fb9d35f9196144d5420 (diff)
downloadperl-f3ec07c74992f83551f19ac514b0c40fd1e93787.tar.gz
avoid extra FETCHes on overloaded qr stringify
/$tied/ called FETCH too many times if the FETCH returned an overloaded object with no qr method, but with stringify fallback
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 527cad9b8b..3a7f38218f 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -176,8 +176,9 @@ PP(pp_regcomp)
PM_SETRE(pm, re);
}
else {
- STRLEN len;
- const char *t = SvOK(tmpstr) ? SvPV_const(tmpstr, len) : "";
+ STRLEN len = 0;
+ const char *t = SvOK(tmpstr) ? SvPV_nomg_const(tmpstr, len) : "";
+
re = PM_GETRE(pm);
assert (re != (REGEXP*) &PL_sv_undef);
@@ -215,6 +216,17 @@ PP(pp_regcomp)
const char *const p = SvPV(tmpstr, len);
tmpstr = newSVpvn_flags(p, len, SVs_TEMP);
}
+ else if (SvAMAGIC(tmpstr)) {
+ /* make a copy to avoid extra stringifies */
+ SV* copy = newSV_type(SVt_PV);
+ sv_setpvn(copy, t, len);
+ if (SvUTF8(tmpstr))
+ SvUTF8_on(copy);
+ else
+ SvUTF8_off(copy);
+ sv_2mortal(copy);
+ tmpstr = copy;
+ }
if (eng)
PM_SETRE(pm, CALLREGCOMP_ENG(eng, tmpstr, pm_flags));