This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: Make slabs sizes powers of two
authorFather Chrysostomos <sprout@cpan.org>
Thu, 12 Jul 2012 21:34:03 +0000 (14:34 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 12 Jul 2012 21:34:03 +0000 (14:34 -0700)
It wasn’t exactly doubling the size of the previous slab, but making
it two less than that.  I’m assuming that malloc implementations round
things up to powers of two, and trying to take advantage of that, so
we don’t have wasted gaps at the ends of slabs.

op.c

diff --git a/op.c b/op.c
index e722b89..7396a19 100644 (file)
--- a/op.c
+++ b/op.c
@@ -222,9 +222,10 @@ Perl_Slab_Alloc(pTHX_ size_t sz)
        /* Create a new slab.  Make this one twice as big. */
        slot = slab2->opslab_first;
        while (slot->opslot_next) slot = slot->opslot_next;
-       slab2 = S_new_slab(aTHX_ DIFF(slab2, slot)*2 > PERL_MAX_SLAB_SIZE
+       slab2 = S_new_slab(aTHX_
+                           (DIFF(slab2, slot)+1)*2 > PERL_MAX_SLAB_SIZE
                                        ? PERL_MAX_SLAB_SIZE
-                                       : DIFF(slab2, slot)*2);
+                                       : (DIFF(slab2, slot)+1)*2);
        slab2->opslab_next = slab->opslab_next;
        slab->opslab_next = slab2;
     }