diff options
author | Richard Leach <richardleach@users.noreply.github.com> | 2022-02-15 01:35:32 +0000 |
---|---|---|
committer | xenu <me@xenu.pl> | 2022-03-07 01:08:53 +0100 |
commit | 7ea8b04b5a0e6952b7ffd5a8fd96468b72da6bea (patch) | |
tree | e86b130304536d6351f130102602d02f52b4d834 /universal.c | |
parent | 8fcb24256a3027cbca7c100825eb3805586fe1e5 (diff) | |
download | perl-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 'universal.c')
-rw-r--r-- | universal.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/universal.c b/universal.c index 9558504317..9c7be3199e 100644 --- a/universal.c +++ b/universal.c @@ -304,12 +304,11 @@ Perl_sv_does_sv(pTHX_ SV *sv, SV *namesv, U32 flags) /* create a PV with value "isa", but with a special address * so that perl knows we're really doing "DOES" instead */ - methodname = newSV_type(SVt_PV); + methodname = newSV_type_mortal(SVt_PV); SvLEN_set(methodname, 0); SvCUR_set(methodname, strlen(PL_isa_DOES)); SvPVX(methodname) = (char *)PL_isa_DOES; /* discard 'const' qualifier */ SvPOK_on(methodname); - sv_2mortal(methodname); call_sv(methodname, G_SCALAR | G_METHOD); SPAGAIN; @@ -1126,7 +1125,7 @@ XS(XS_NamedCapture_TIEHASH) flag = SvTRUE(mark[1]) ? RXapif_ALL : RXapif_ONE; mark += 2; } - ST(0) = sv_2mortal(newSV_type(SVt_IV)); + ST(0) = newSV_type_mortal(SVt_IV); sv_setuv(newSVrv(ST(0), package), flag); } XSRETURN(1); |