summaryrefslogtreecommitdiff
path: root/av.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-08-19 11:57:17 -0600
committerKarl Williamson <khw@cpan.org>2020-08-19 16:12:19 -0600
commit87306e0674dfe3af29804b4641347cd5ac9b0521 (patch)
tree8693933fae0918d3570f6d4d412ac8d91eea5160 /av.c
parent62066149de47fdbff345b71823d783ffad25933f (diff)
downloadperl-87306e0674dfe3af29804b4641347cd5ac9b0521.tar.gz
Add av_count()
This returns the number of elements in an array in a clearly named function. av_top_index(), av_tindex() are clearly named, but are less than ideal, and came about because no one back then thought of this one, until now Paul Evans did.
Diffstat (limited to 'av.c')
-rw-r--r--av.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/av.c b/av.c
index 27b2f12032..b5ddacaf4f 100644
--- a/av.c
+++ b/av.c
@@ -814,9 +814,10 @@ The Perl equivalent for this is C<$#myarray>.
=for apidoc av_len
Same as L</av_top_index>. Note that, unlike what the name implies, it returns
-the highest index in the array, so to get the size of the array you need to use
-S<C<av_len(av) + 1>>. This is unlike L</sv_len>, which returns what you would
-expect.
+the highest index in the array. This is unlike L</sv_len>, which returns what
+you would expect.
+
+B<To get the true number of elements in the array, instead use C<L</av_count>>>.
=cut
*/
@@ -1089,6 +1090,16 @@ Perl_av_nonelem(pTHX_ AV *av, SSize_t ix) {
return sv;
}
+SSize_t
+Perl_av_top_index(pTHX_ AV *av)
+{
+ PERL_ARGS_ASSERT_AV_TOP_INDEX;
+ assert(SvTYPE(av) == SVt_PVAV);
+
+ return AvFILL(av);
+}
+
+
/*
* ex: set ts=8 sts=4 sw=4 et:
*/