summaryrefslogtreecommitdiff
path: root/inline.h
diff options
context:
space:
mode:
authorRichard Leach <richardleach@users.noreply.github.com>2022-03-20 14:11:15 +0000
committerKarl Williamson <khw@cpan.org>2022-06-08 09:41:44 -0600
commita9b64e60085410a21f22d9df311cfe251b44d446 (patch)
treed339ed88d88c2d5260924c503a0d0e5ef8befb55 /inline.h
parent37a94617085a82b7af352df83dfd5eb4788aa27b (diff)
downloadperl-a9b64e60085410a21f22d9df311cfe251b44d446.tar.gz
inline.h: add av_push_simple
A simplified version of av_push, along the lines of av_store_simple and av_fetch_simple. This function is trivial, but having it makes refactoring of existing code easier to read. For example, changing: av_push(some_av, val); to: av_push_simple(some_av,val); is easier to read than: av_store_simple(some_av, AvFILLp(some_av) + 1, val)
Diffstat (limited to 'inline.h')
-rw-r--r--inline.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/inline.h b/inline.h
index 11623071b7..863d8570ad 100644
--- a/inline.h
+++ b/inline.h
@@ -140,6 +140,35 @@ Perl_av_fetch_simple(pTHX_ AV *av, SSize_t key, I32 lval)
}
}
+/*
+=for apidoc av_push_simple
+
+This is a cut-down version of av_push that assumes that the array is very
+straightforward - no magic, not readonly, and AvREAL - and that C<key> is
+not less than -1. This function MUST NOT be used in situations where any
+of those assumptions may not hold.
+
+Pushes an SV (transferring control of one reference count) onto the end of the
+array. The array will grow automatically to accommodate the addition.
+
+Perl equivalent: C<push @myarray, $val;>.
+
+=cut
+*/
+
+PERL_STATIC_INLINE void
+Perl_av_push_simple(pTHX_ AV *av, SV *val)
+{
+ PERL_ARGS_ASSERT_AV_PUSH_SIMPLE;
+ assert(SvTYPE(av) == SVt_PVAV);
+ assert(!SvMAGICAL(av));
+ assert(!SvREADONLY(av));
+ assert(AvREAL(av));
+ assert(AvFILLp(av) > -2);
+
+ (void)av_store_simple(av,AvFILLp(av)+1,val);
+}
+
/* ------------------------------- cv.h ------------------------------- */
/*