[svn:parrot] r49181 - branches/gc_massacre/src/gc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Mon Sep 20 20:14:06 UTC 2010


Author: chromatic
Date: Mon Sep 20 20:14:05 2010
New Revision: 49181
URL: https://trac.parrot.org/parrot/changeset/49181

Log:
[GC] Optimized fixed-size allocation function.

A bit of rearranging and consting gives a modest 0.55% performance improvement
in this hot path; not bad for two minutes of work.

Modified:
   branches/gc_massacre/src/gc/fixed_allocator.c

Modified: branches/gc_massacre/src/gc/fixed_allocator.c
==============================================================================
--- branches/gc_massacre/src/gc/fixed_allocator.c	Mon Sep 20 17:57:30 2010	(r49180)
+++ branches/gc_massacre/src/gc/fixed_allocator.c	Mon Sep 20 20:14:05 2010	(r49181)
@@ -112,34 +112,36 @@
     ASSERT_ARGS(Parrot_gc_fixed_allocator_allocate)
 
     /* We always align size to 4/8 bytes. */
-    size_t  index, alloc_size;
+    const size_t index = (size - 1) / sizeof (void *);
     void   *ret;
     PARROT_ASSERT(size);
-    index      = (size - 1) / sizeof (void*);
-    alloc_size = (index + 1) * sizeof (void *);
 
     if (index >= allocator->num_pools) {
         size_t new_size = index + 1;
         /* (re)allocate pools */
         if (allocator->num_pools)
             allocator->pools = mem_internal_realloc_n_zeroed_typed(
-                                allocator->pools, new_size, allocator->num_pools, Pool_Allocator*);
+                                    allocator->pools, new_size,
+                                    allocator->num_pools, Pool_Allocator *);
         else
-            allocator->pools = mem_internal_allocate_n_zeroed_typed(new_size, Pool_Allocator*);
+            allocator->pools = mem_internal_allocate_n_zeroed_typed(new_size,
+                                    Pool_Allocator *);
 
         allocator->num_pools = new_size;
     }
 
-    if (allocator->pools[index] == NULL)
+    if (! allocator->pools[index]) {
+        const size_t alloc_size = (index + 1) * sizeof (void *);
         allocator->pools[index] = Parrot_gc_pool_new(interp, alloc_size);
+    }
 
     ret = pool_allocate(allocator->pools[index]);
-    /*
-     * memset(ret, 0, alloc_size);
-     */
+
+    /* memset ret to 0 here? */
     return ret;
 }
 
+
 PARROT_EXPORT
 void
 Parrot_gc_fixed_allocator_free(PARROT_INTERP,


More information about the parrot-commits mailing list