summaryrefslogtreecommitdiff
path: root/pp_hot.c
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-02-15 01:35:32 +0000
committerxenu <me@xenu.pl>2022-03-07 01:08:53 +0100
commit7ea8b04b5a0e6952b7ffd5a8fd96468b72da6bea (patch)
treee86b130304536d6351f130102602d02f52b4d834 /pp_hot.c
parent8fcb24256a3027cbca7c100825eb3805586fe1e5 (diff)
downloadperl-7ea8b04b5a0e6952b7ffd5a8fd96468b72da6bea.tar.gz
Perl_newSV_type_mortal - new inline function introduced and used
There's no efficient way to create a mortal SV of any type other than SVt_NULL (via sv_newmortal). The options are either to do: * SV* sv = sv_newmortal; sv_upgrade(sv, SVt_SOMETYPE); but sv_upgrade is needlessly inefficient on new SVs. * SV* sv = sv_2mortal(newSV_type(SVt_SOMETYPE) but this will perform runtime checks to see if (sv) and if (SvIMMORTAL(sv), and for a new SV we know that those answers will always be yes and no. This commit adds a new inline function which is basically a mortalizing wrapper around the now-inlined newSV_type.
Diffstat (limited to 'pp_hot.c')
-rw-r--r--pp_hot.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/pp_hot.c b/pp_hot.c
index ebd4b47e5d..67b255e2e7 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -991,7 +991,7 @@ PP(pp_multiconcat)
)
)
{
- SV *tmp = sv_newmortal();
+ SV *tmp = newSV_type_mortal(SVt_PV);
sv_copypv(tmp, left);
SvSETMAGIC(tmp);
left = tmp;
@@ -2868,7 +2868,7 @@ PP(pp_qr)
REGEXP * rx = PM_GETRE(pm);
regexp *prog = ReANY(rx);
SV * const pkg = RXp_ENGINE(prog)->qr_package(aTHX_ (rx));
- SV * const rv = sv_newmortal();
+ SV * const rv = newSV_type_mortal(SVt_IV);
CV **cvp;
CV *cv;
@@ -3406,8 +3406,7 @@ PP(pp_helem)
if (!defer) {
DIE(aTHX_ PL_no_helem_sv, SVfARG(keysv));
}
- lv = sv_newmortal();
- sv_upgrade(lv, SVt_PVLV);
+ lv = newSV_type_mortal(SVt_PVLV);
LvTYPE(lv) = 'y';
sv_magic(lv, key2 = newSVsv(keysv), PERL_MAGIC_defelem, NULL, 0);
SvREFCNT_dec_NN(key2); /* sv_magic() increments refcount */
@@ -3846,8 +3845,7 @@ PP(pp_multideref)
SV* key2;
if (!defer)
DIE(aTHX_ PL_no_helem_sv, SVfARG(keysv));
- lv = sv_newmortal();
- sv_upgrade(lv, SVt_PVLV);
+ lv = newSV_type_mortal(SVt_PVLV);
LvTYPE(lv) = 'y';
sv_magic(lv, key2 = newSVsv(keysv),
PERL_MAGIC_defelem, NULL, 0);