diff options
author | Nicholas Clark <nick@ccl4.org> | 2007-01-29 18:28:16 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2007-01-29 18:28:16 +0000 |
commit | 29a861e74521a5f903bccb023c86950d733fa0b7 (patch) | |
tree | 30399e656738dc7add2288fa2aebd589eeaaf041 /av.c | |
parent | e30fbb82116d47ef2569f2af20359965dc7fcae1 (diff) | |
download | perl-29a861e74521a5f903bccb023c86950d733fa0b7.tar.gz |
Add av_create_and_push() and av_create_and_unshift_one() to refactor
out two repeated idioms.
p4raw-id: //depot/perl@30064
Diffstat (limited to 'av.c')
-rw-r--r-- | av.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -487,6 +487,24 @@ Perl_av_undef(pTHX_ register AV *av) } /* + +=for apidoc av_create_and_push + +Push an SV onto the end of the array, creating the array if necessary. +A small internal helper function to remove a commonly duplicated idiom. + +=cut +*/ + +void +Perl_av_create_and_push(pTHX_ AV **const avp, SV *const val) +{ + if (!*avp) + *avp = newAV(); + av_push(*avp, val); +} + +/* =for apidoc av_push Pushes an SV onto the end of the array. The array will grow automatically @@ -568,6 +586,26 @@ Perl_av_pop(pTHX_ register AV *av) } /* + +=for apidoc av_create_and_unshift_one + +Unshifts an SV onto the beginning of the array, creating the array if +necessary. +A small internal helper function to remove a commonly duplicated idiom. + +=cut +*/ + +SV ** +Perl_av_create_and_unshift_one(pTHX_ AV **const avp, SV *const val) +{ + if (!*avp) + *avp = newAV(); + av_unshift(*avp, 1); + return av_store(*avp, 0, val); +} + +/* =for apidoc av_unshift Unshift the given number of C<undef> values onto the beginning of the |