X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=av.c;h=39b4b7d3270c499da85572b294997490e6c6e348;hb=b8884ce4af9d0f622732315808561f174bd9be0c;hp=22eb6716f26450c6cd210b9167673f9c9d54cf9e;hpb=9c6bc640227cd4fa081b32554378abe794cacfc0;p=p5sagit%2Fp5-mst-13.2.git diff --git a/av.c b/av.c index 22eb671..39b4b7d 100644 --- a/av.c +++ b/av.c @@ -362,9 +362,7 @@ Creates a new AV. The reference count is set to 1. AV * Perl_newAV(pTHX) { - register AV * const av = (AV*)newSV(0); - - sv_upgrade((SV *)av, SVt_PVAV); + register AV * const av = (AV*)newSV_type(SVt_PVAV); /* sv_upgrade does AvREAL_only() */ AvALLOC(av) = 0; AvARRAY(av) = NULL; @@ -385,9 +383,7 @@ will have a reference count of 1. AV * Perl_av_make(pTHX_ register I32 size, register SV **strp) { - register AV * const av = (AV*)newSV(0); - - sv_upgrade((SV *) av,SVt_PVAV); + register AV * const av = (AV*)newSV_type(SVt_PVAV); /* sv_upgrade does AvREAL_only() */ if (size) { /* "defined" was returning undef for size==0 anyway. */ register SV** ary; @@ -487,6 +483,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 +582,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 values onto the beginning of the