[perl #50538] when( @n && %n ) fails to smart match
[p5sagit/p5-mst-13.2.git] / av.c
diff --git a/av.c b/av.c
index cf95d61..fa2be12 100644 (file)
--- a/av.c
+++ b/av.c
@@ -117,8 +117,22 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
                IV itmp;
 #endif
 
-#ifdef MYMALLOC
-               newmax = malloced_size((void*)AvALLOC(av))/sizeof(SV*) - 1;
+#ifdef Perl_safesysmalloc_size
+               /* Whilst it would be quite possible to move this logic around
+                  (as I did in the SV code), so as to set AvMAX(av) early,
+                  based on calling Perl_safesysmalloc_size() immediately after
+                  allocation, I'm not convinced that it is a great idea here.
+                  In an array we have to loop round setting everything to
+                  &PL_sv_undef, which means writing to memory, potentially lots
+                  of it, whereas for the SV buffer case we don't touch the
+                  "bonus" memory. So there there is no cost in telling the
+                  world about it, whereas here we have to do work before we can
+                  tell the world about it, and that work involves writing to
+                  memory that might never be read. So, I feel, better to keep
+                  the current lazy system of only writing to it if our caller
+                  has a need for more space. NWC  */
+               newmax = Perl_safesysmalloc_size((void*)AvALLOC(av)) /
+                   sizeof(SV*) - 1;
 
                if (key <= newmax) 
                    goto resized;
@@ -147,7 +161,7 @@ Perl_av_extend(pTHX_ AV *av, I32 key)
                    Safefree(AvALLOC(av));
                AvALLOC(av) = ary;
 #endif
-#ifdef MYMALLOC
+#ifdef Perl_safesysmalloc_size
              resized:
 #endif
                ary = AvALLOC(av) + AvMAX(av) + 1;