When reusing op slots, only zero as much as needed
authorFather Chrysostomos <sprout@cpan.org>
Thu, 28 Jun 2012 05:40:48 +0000 (22:40 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jun 2012 07:21:01 +0000 (00:21 -0700)
If an op slot is reused for a smaller op, we only need to zero out the
space used for the op, not the whole slot.

op.c

diff --git a/op.c b/op.c
index bfcd83c..5de86a1 100644 (file)
--- a/op.c
+++ b/op.c
@@ -332,7 +332,7 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
     OPSLAB *slab2;
     OPSLOT *slot;
     OP *o;
-    size_t space;
+    size_t opsz, space;
 
     if (!PL_compcv || CvROOT(PL_compcv)
      || (CvSTART(PL_compcv) && !CvSLABBED(PL_compcv)))
@@ -346,7 +346,8 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
     }
     else ++(slab = (OPSLAB *)CvSTART(PL_compcv))->opslab_refcnt;
 
-    sz = SIZE_TO_PSIZE(sz) + OPSLOT_HEADER_P;
+    opsz = SIZE_TO_PSIZE(sz);
+    sz = opsz + OPSLOT_HEADER_P;
 
     if (slab->opslab_freed) {
        OP **too = &slab->opslab_freed;
@@ -359,7 +360,7 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
        }
        if (o) {
            *too = o->op_next;
-           Zero(o, DIFF(o, OpSLOT(o)->opslot_next), I32 *);
+           Zero(o, opsz, I32 *);
            o->op_slabbed = 1;
            return (void *)o;
        }