summaryrefslogtreecommitdiff
path: root/inline.h
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 /inline.h
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 'inline.h')
-rw-r--r--inline.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/inline.h b/inline.h
index 8e9bef52b1..a8240efb9c 100644
--- a/inline.h
+++ b/inline.h
@@ -39,13 +39,21 @@ SOFTWARE.
/* ------------------------------- av.h ------------------------------- */
-PERL_STATIC_INLINE SSize_t
-Perl_av_top_index(pTHX_ AV *av)
+/*
+=for apidoc av_count
+Returns the number of elements in the array C<av>. This is the true length of
+the array, including any undefined elements. It is always the same as
+S<C<av_top_index(av) + 1>>.
+
+=cut
+*/
+PERL_STATIC_INLINE Size_t
+Perl_av_count(pTHX_ AV *av)
{
- PERL_ARGS_ASSERT_AV_TOP_INDEX;
+ PERL_ARGS_ASSERT_AV_COUNT;
assert(SvTYPE(av) == SVt_PVAV);
- return AvFILL(av);
+ return AvFILL(av) + 1;
}
/* ------------------------------- cv.h ------------------------------- */