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 /pp.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 'pp.c')
-rw-r--r-- | pp.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -313,7 +313,7 @@ PP(pp_pos) dSP; dTOPss; if (PL_op->op_flags & OPf_MOD || LVRET) { - SV * const ret = sv_2mortal(newSV_type(SVt_PVLV));/* Not TARG RT#67838 */ + SV * const ret = newSV_type_mortal(SVt_PVLV);/* Not TARG RT#67838 */ sv_magic(ret, NULL, PERL_MAGIC_pos, NULL, 0); LvTYPE(ret) = '.'; LvTARG(ret) = SvREFCNT_inc_simple(sv); @@ -467,7 +467,7 @@ S_refto(pTHX_ SV *sv) SvTEMP_off(sv); SvREFCNT_inc_void_NN(sv); } - rv = sv_newmortal(); + rv = newSV_type_mortal(SVt_IV); sv_setrv_noinc(rv, sv); return rv; } @@ -3300,7 +3300,7 @@ PP(pp_substr) } if (lvalue && !repl_sv) { SV * ret; - ret = sv_2mortal(newSV_type(SVt_PVLV)); /* Not TARG RT#67838 */ + ret = newSV_type_mortal(SVt_PVLV); /* Not TARG RT#67838 */ sv_magic(ret, NULL, PERL_MAGIC_substr, NULL, 0); LvTYPE(ret) = 'x'; LvTARG(ret) = SvREFCNT_inc_simple(sv); @@ -3432,7 +3432,7 @@ PP(pp_vec) retuv = errflags ? 0 : do_vecget(src, offset, size); if (lvalue) { /* it's an lvalue! */ - ret = sv_2mortal(newSV_type(SVt_PVLV)); /* Not TARG RT#67838 */ + ret = newSV_type_mortal(SVt_PVLV); /* Not TARG RT#67838 */ sv_magic(ret, NULL, PERL_MAGIC_vec, NULL, 0); LvTYPE(ret) = 'v'; LvTARG(ret) = SvREFCNT_inc_simple(src); @@ -6830,7 +6830,7 @@ PP(pp_refassign) PP(pp_lvref) { dSP; - SV * const ret = sv_2mortal(newSV_type(SVt_PVMG)); + SV * const ret = newSV_type_mortal(SVt_PVMG); SV * const elem = PL_op->op_private & OPpLVREF_ELEM ? POPs : NULL; SV * const arg = PL_op->op_flags & OPf_STACKED ? POPs : NULL; MAGIC * const mg = sv_magicext(ret, arg, PERL_MAGIC_lvref, @@ -6898,7 +6898,7 @@ PP(pp_lvrefslice) else S_localise_helem_lval(aTHX_ (HV *)av, elemsv, can_preserve); } - *MARK = sv_2mortal(newSV_type(SVt_PVMG)); + *MARK = newSV_type_mortal(SVt_PVMG); sv_magic(*MARK,(SV *)av,PERL_MAGIC_lvref,(char *)elemsv,HEf_SVKEY); } RETURN; |