Enlarge the last slot on an op slab to fit
authorFather Chrysostomos <sprout@cpan.org>
Tue, 26 Jun 2012 20:24:13 +0000 (13:24 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 29 Jun 2012 07:21:00 +0000 (00:21 -0700)
For simplicity, op slots are never resized once they are allocated.
But they are reused after they are freed, if they are big enough.

When allocating the last op slot that will fit on a slab, we might as
well enlarge the slot to contain whatever space is left over, so this
slot, after being freed, can be reused for a larger op.

op.c

diff --git a/op.c b/op.c
index 874df5f..67f0cf1 100644 (file)
--- a/op.c
+++ b/op.c
@@ -397,6 +397,9 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
     /* Create a new op slot */
     slot = (OPSLOT *)((I32 **)slab2->opslab_first - sz);
     assert(slot >= &slab2->opslab_slots);
+    if (DIFF(&slab2->opslab_slots, slot)
+        < SIZE_TO_PSIZE(sizeof(OP)) + OPSLOT_HEADER_P)
+       slot = &slab2->opslab_slots;
     INIT_OPSLOT;
     DEBUG_S(Perl_warn(aTHX_ "allocating op at %p, slab %p", o, slab));
     return (void *)o;