summaryrefslogtreecommitdiff
path: root/pad.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 /pad.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 'pad.c')
-rw-r--r--pad.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/pad.c b/pad.c
index 5d34240d1a..e0131ac698 100644
--- a/pad.c
+++ b/pad.c
@@ -1252,13 +1252,13 @@ S_pad_findlex(pTHX_ const char *namepv, STRLEN namelen, U32 flags, const CV* cv,
}
if (!*out_capture) {
if (namelen != 0 && *namepv == '@')
- *out_capture = sv_2mortal(MUTABLE_SV(newAV()));
+ *out_capture = newSV_type_mortal(SVt_PVAV);
else if (namelen != 0 && *namepv == '%')
- *out_capture = sv_2mortal(MUTABLE_SV(newHV()));
+ *out_capture = newSV_type_mortal(SVt_PVHV);
else if (namelen != 0 && *namepv == '&')
- *out_capture = sv_2mortal(newSV_type(SVt_PVCV));
+ *out_capture = newSV_type_mortal(SVt_PVCV);
else
- *out_capture = sv_newmortal();
+ *out_capture = newSV_type_mortal(SVt_NULL);
}
}
@@ -2068,7 +2068,7 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside, HV *cloned,
*/
bool cloned_in_this_pass;
if (!cloned)
- cloned = (HV *)sv_2mortal((SV *)newHV());
+ cloned = (HV *)newSV_type_mortal(SVt_PVHV);
do {
cloned_in_this_pass = FALSE;
for (ix = fpad; ix > 0; ix--) {