From: Ben Tilly Date: Tue, 21 Nov 2000 23:29:31 +0000 (-0500) Subject: Re: av.c patch (having slight problems) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e2b534e73737788b0d66a6d8380a5af970286238;p=p5sagit%2Fp5-mst-13.2.git Re: av.c patch (having slight problems) Message-ID: unshift() speedup. p4raw-id: //depot/perl@7825 --- diff --git a/av.c b/av.c index 777651d..e5f6dc8 100644 --- a/av.c +++ b/av.c @@ -554,6 +554,7 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num) register I32 i; register SV **ary; MAGIC* mg; + I32 slide; if (!av || num <= 0) return; @@ -591,6 +592,9 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num) } if (num) { i = AvFILLp(av); + /* Create extra elements */ + slide = i > 0 ? i : 0; + num += slide; av_extend(av, i + num); AvFILLp(av) += num; ary = AvARRAY(av); @@ -598,6 +602,10 @@ Perl_av_unshift(pTHX_ register AV *av, register I32 num) do { ary[--num] = &PL_sv_undef; } while (num); + /* Make extra elements into a buffer */ + AvMAX(av) -= slide; + AvFILLp(av) -= slide; + SvPVX(av) = (char*)(AvARRAY(av) + slide); } }