summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-03-20 15:22:27 +0000
committerKarl Williamson <khw@cpan.org>2022-06-08 09:41:44 -0600
commiteae3cc9643eecd5d8b27c8fb4a3dc3bfebaf57e3 (patch)
treef391916870180d03e3af0e59ae164360c2615c02
parenta9b64e60085410a21f22d9df311cfe251b44d446 (diff)
downloadperl-eae3cc9643eecd5d8b27c8fb4a3dc3bfebaf57e3.tar.gz
Move av_new_alloc from av.c to inline.h
There was less benefit in doing this prior to newSV_type becoming an inline function. Now that it is, inlining av_new_alloc can help compilers eliminate redundant setting of AvMAX/AvFILLp and unnecessary branches of any following inlined calls to av_store_simple.
-rw-r--r--av.c42
-rw-r--r--embed.fnc2
-rw-r--r--inline.h43
-rw-r--r--proto.h4
4 files changed, 47 insertions, 44 deletions
diff --git a/av.c b/av.c
index 090c5a93f4..81a7f19219 100644
--- a/av.c
+++ b/av.c
@@ -393,48 +393,6 @@ Perl_av_store(pTHX_ AV *av, SSize_t key, SV *val)
}
/*
-=for apidoc av_new_alloc
-
-This implements L<perlapi/C<newAV_alloc_x>>
-and L<perlapi/C<newAV_alloc_xz>>, which are the public API for this
-functionality.
-
-Creates a new AV and allocates its SV* array.
-
-This is similar to, but more efficient than doing:
-
- AV *av = newAV();
- av_extend(av, key);
-
-The size parameter is used to pre-allocate a SV* array large enough to
-hold at least elements C<0..(size-1)>. C<size> must be at least 1.
-
-The C<zeroflag> parameter controls whether or not the array is NULL
-initialized.
-
-=cut
-*/
-
-AV *
-Perl_av_new_alloc(pTHX_ SSize_t size, bool zeroflag)
-{
- AV * const av = newAV();
- SV** ary;
- PERL_ARGS_ASSERT_AV_NEW_ALLOC;
- assert(size > 0);
-
- Newx(ary, size, SV*); /* Newx performs the memwrap check */
- AvALLOC(av) = ary;
- AvARRAY(av) = ary;
- AvMAX(av) = size - 1;
-
- if (zeroflag)
- Zero(ary, size, SV*);
-
- return av;
-}
-
-/*
=for apidoc av_make
Creates a new AV and populates it with a list (C<**strp>, length C<size>) of
diff --git a/embed.fnc b/embed.fnc
index 52e8f0977b..306b42b43a 100644
--- a/embed.fnc
+++ b/embed.fnc
@@ -640,7 +640,7 @@ CipdR |SV** |av_fetch_simple|NN AV *av|SSize_t key|I32 lval
Apd |void |av_fill |NN AV *av|SSize_t fill
ApdR |SSize_t|av_len |NN AV *av
ApdR |AV* |av_make |SSize_t size|NN SV **strp
-CpdR |AV* |av_new_alloc |SSize_t size|bool zeroflag
+CipdR |AV* |av_new_alloc |SSize_t size|bool zeroflag
p |SV* |av_nonelem |NN AV *av|SSize_t ix
Apd |SV* |av_pop |NN AV *av
Apdoe |void |av_create_and_push|NN AV **const avp|NN SV *const val
diff --git a/inline.h b/inline.h
index 863d8570ad..9301a77d9c 100644
--- a/inline.h
+++ b/inline.h
@@ -169,6 +169,49 @@ Perl_av_push_simple(pTHX_ AV *av, SV *val)
(void)av_store_simple(av,AvFILLp(av)+1,val);
}
+/*
+=for apidoc av_new_alloc
+
+This implements L<perlapi/C<newAV_alloc_x>>
+and L<perlapi/C<newAV_alloc_xz>>, which are the public API for this
+functionality.
+
+Creates a new AV and allocates its SV* array.
+
+This is similar to, but more efficient than doing:
+
+ AV *av = newAV();
+ av_extend(av, key);
+
+The size parameter is used to pre-allocate a SV* array large enough to
+hold at least elements C<0..(size-1)>. C<size> must be at least 1.
+
+The C<zeroflag> parameter controls whether or not the array is NULL
+initialized.
+
+=cut
+*/
+
+PERL_STATIC_INLINE AV *
+Perl_av_new_alloc(pTHX_ SSize_t size, bool zeroflag)
+{
+ AV * const av = newAV();
+ SV** ary;
+ PERL_ARGS_ASSERT_AV_NEW_ALLOC;
+ assert(size > 0);
+
+ Newx(ary, size, SV*); /* Newx performs the memwrap check */
+ AvALLOC(av) = ary;
+ AvARRAY(av) = ary;
+ AvMAX(av) = size - 1;
+
+ if (zeroflag)
+ Zero(ary, size, SV*);
+
+ return av;
+}
+
+
/* ------------------------------- cv.h ------------------------------- */
/*
diff --git a/proto.h b/proto.h
index 6bad23d35a..050697fff5 100644
--- a/proto.h
+++ b/proto.h
@@ -313,9 +313,11 @@ PERL_CALLCONV AV* Perl_av_make(pTHX_ SSize_t size, SV **strp)
#define PERL_ARGS_ASSERT_AV_MAKE \
assert(strp)
-PERL_CALLCONV AV* Perl_av_new_alloc(pTHX_ SSize_t size, bool zeroflag)
+#ifndef PERL_NO_INLINE_FUNCTIONS
+PERL_STATIC_INLINE AV* Perl_av_new_alloc(pTHX_ SSize_t size, bool zeroflag)
__attribute__warn_unused_result__;
#define PERL_ARGS_ASSERT_AV_NEW_ALLOC
+#endif
PERL_CALLCONV SV* Perl_av_nonelem(pTHX_ AV *av, SSize_t ix);
#define PERL_ARGS_ASSERT_AV_NONELEM \