summaryrefslogtreecommitdiff
path: root/sv_inline.h
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-08-02 22:12:58 +0000
committerKarl Williamson <khw@cpan.org>2022-08-05 13:53:23 -0600
commit819d09b57c6a76b0ba90670a1ea1861730bc457b (patch)
treefd512bb44f4974294eaf52be471beee71c5d1cfc /sv_inline.h
parent36d1e5f3076514e5256e1424ae48d255572178a0 (diff)
downloadperl-819d09b57c6a76b0ba90670a1ea1861730bc457b.tar.gz
Perl_newRV_noinc - explicitly simplify, convert to inline func
Perl_newRV_noinc creates a new SVt_IV, then calls sv_setrv_noinc, which will check if the SVt_IV is SvTHINKFIRST (it won't be) and if it is types other than SVt_IV (it won't be). If those checks and associated branches are removed, all that remains is some flag twiddling and setting the sv_u.svu_rv pointer. A decent compiler *might* figure that all out and simplify Perl_newRV_noinc right down to the essentials, but if we do that directly, the entire function is small enough to move to sv_inline.h
Diffstat (limited to 'sv_inline.h')
-rw-r--r--sv_inline.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/sv_inline.h b/sv_inline.h
index c92bff366a..574334881c 100644
--- a/sv_inline.h
+++ b/sv_inline.h
@@ -929,5 +929,30 @@ Perl_SvPV_helper(pTHX_
}
/*
+=for apidoc newRV_noinc
+
+Creates an RV wrapper for an SV. The reference count for the original
+SV is B<not> incremented.
+
+=cut
+*/
+
+PERL_STATIC_INLINE SV *
+Perl_newRV_noinc(pTHX_ SV *const tmpRef)
+{
+ SV *sv = newSV_type(SVt_IV);
+
+ PERL_ARGS_ASSERT_NEWRV_NOINC;
+
+ SvTEMP_off(tmpRef);
+
+ /* inlined, simplified sv_setrv_noinc(sv, tmpRef); */
+ SvRV_set(sv, tmpRef);
+ SvROK_on(sv);
+
+ return sv;
+}
+
+/*
* ex: set ts=8 sts=4 sw=4 et:
*/