From 8fcb24256a3027cbca7c100825eb3805586fe1e5 Mon Sep 17 00:00:00 2001 From: Richard Leach Date: Wed, 9 Feb 2022 21:53:55 +0000 Subject: Inlined newSV_type(SVt_NULL) leaner than non-inlined newSV(0) When a function outside of sv.c creates a SV via newSV(0): * There is a call to Perl_newSV * A SV head is uprooted and its flags set * A runtime check is made to effectively see if 0 > 0 * The new SV* is returned Replacing newSV(0) with newSV_type(SVt_NULL) should be more efficient, because (assuming there are SV heads to uproot), the only step is: * A SV head is uprooted and its flags set --- av.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'av.c') diff --git a/av.c b/av.c index d2f0e0db45..65c2246c62 100644 --- a/av.c +++ b/av.c @@ -292,7 +292,7 @@ Perl_av_fetch(pTHX_ AV *av, SSize_t key, I32 lval) if (!AvARRAY(av)[key]) { emptyness: - return lval ? av_store(av,key,newSV(0)) : NULL; + return lval ? av_store(av,key,newSV_type(SVt_NULL)) : NULL; } return &AvARRAY(av)[key]; @@ -473,7 +473,7 @@ Perl_av_make(pTHX_ SSize_t size, SV **strp) SvGETMAGIC(*strp); /* before newSV, in case it dies */ AvFILLp(av)++; - ary[i] = newSV(0); + ary[i] = newSV_type(SVt_NULL); sv_setsv_flags(ary[i], *strp, SV_DO_COW_SVSETSV|SV_NOSTEAL); strp++; @@ -1124,7 +1124,7 @@ Perl_av_iter_p(pTHX_ AV *av) { SV * Perl_av_nonelem(pTHX_ AV *av, SSize_t ix) { - SV * const sv = newSV(0); + SV * const sv = newSV_type(SVt_NULL); PERL_ARGS_ASSERT_AV_NONELEM; if (!av_store(av,ix,sv)) return sv_2mortal(sv); /* has tie magic */ -- cgit v1.2.1