From 7ea8b04b5a0e6952b7ffd5a8fd96468b72da6bea Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Tue, 15 Feb 2022 01:35:32 +0000 Subject: 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. --- mg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mg.c') diff --git a/mg.c b/mg.c index 5f3eeae4fe..c470beaec1 100644 --- a/mg.c +++ b/mg.c @@ -877,7 +877,7 @@ Perl_sv_string_from_errnum(pTHX_ int errnum, SV *tgtsv) { char const *errstr; if(!tgtsv) - tgtsv = sv_newmortal(); + tgtsv = newSV_type_mortal(SVt_PV); errstr = my_strerror(errnum); if(errstr) { sv_setpv(tgtsv, errstr); -- cgit v1.2.1