This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_entersub optimization
authorSalvador Fandino <sfandino@yahoo.com>
Tue, 12 Mar 2013 14:04:35 +0000 (14:04 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 12 Mar 2013 14:56:27 +0000 (14:56 +0000)
There is code in pp_entersub() that specifically handles the case where
AvARRAY(@_) != AvALLOC(@_), and tries to be more efficient than just
realloc()ing AvALLOC().

However, @_'s that have been shifted or messed with are usually cleaned up
or abandoned by CLEAR_ARGARRAY/POPSUB anyway, so this code is (probably)
never called.  So remove it.
In a worst case, it would just mean that realloc() is called
unnecessarily, which would be slower, but still correct.

pp_hot.c

index ad99c42..8871593 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2807,19 +2807,14 @@ try_autoload:
            cx->blk_sub.argarray = av;
            ++MARK;
 
-           if (items > AvMAX(av) + 1) {
-               SV **ary = AvALLOC(av);
-               if (AvARRAY(av) != ary) {
-                   AvMAX(av) += AvARRAY(av) - AvALLOC(av);
-                   AvARRAY(av) = ary;
-               }
-               if (items > AvMAX(av) + 1) {
-                   AvMAX(av) = items - 1;
-                   Renew(ary,items,SV*);
-                   AvALLOC(av) = ary;
-                   AvARRAY(av) = ary;
-               }
-           }
+           if (items - 1 > AvMAX(av)) {
+                SV **ary = AvALLOC(av);
+                AvMAX(av) = items - 1;
+                Renew(ary, items, SV*);
+                AvALLOC(av) = ary;
+                AvARRAY(av) = ary;
+            }
+
            Copy(MARK,AvARRAY(av),items,SV*);
            AvFILLp(av) = items - 1;