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

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


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

Log:
[GC] Optimized pool_allocate()'s branch conditions.

Introducing two static functions and rewriting the recursive condition
clarifies the function *and* gives another half-percent performance improvement
thanks to this being a hot path.

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 20:14:08 2010	(r49182)
+++ branches/gc_massacre/src/gc/fixed_allocator.c	Mon Sep 20 20:14:11 2010	(r49183)
@@ -28,7 +28,17 @@
         __attribute__nonnull__(1);
 
 PARROT_CANNOT_RETURN_NULL
-static void* pool_allocate(ARGMOD(Pool_Allocator *pool))
+static void * get_free_list_item(ARGMOD(Pool_Allocator *pool))
+        __attribute__nonnull__(1)
+        FUNC_MODIFIES(*pool);
+
+PARROT_CANNOT_RETURN_NULL
+static void * get_newfree_list_item(ARGMOD(Pool_Allocator *pool))
+        __attribute__nonnull__(1)
+        FUNC_MODIFIES(*pool);
+
+PARROT_CANNOT_RETURN_NULL
+static void * pool_allocate(ARGMOD(Pool_Allocator *pool))
         __attribute__nonnull__(1)
         FUNC_MODIFIES(*pool);
 
@@ -45,6 +55,10 @@
        PARROT_ASSERT_ARG(pool))
 #define ASSERT_ARGS_arena_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_get_free_list_item __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(pool))
+#define ASSERT_ARGS_get_newfree_list_item __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(pool))
 #define ASSERT_ARGS_pool_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(pool))
 #define ASSERT_ARGS_pool_free __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -159,6 +173,7 @@
 }
 
 /*
+
 =back
 
 =head1 PoolAllocator METHODS
@@ -259,8 +274,14 @@
     return pool_is_owned(pool, ptr);
 }
 
+
 /*
-=item C<static void* pool_allocate(Pool_Allocator *pool)>
+
+=item C<static void * pool_allocate(Pool_Allocator *pool)>
+
+=item C<static void * get_free_list_item(Pool_Allocator *pool)>
+
+=item C<static void * get_newfree_list_item(Pool_Allocator *pool)>
 
 =item C<static void pool_free(Pool_Allocator *pool, void *data)>
 
@@ -269,29 +290,48 @@
 Static implementation of public methods.
 
 =cut
+
 */
 
 PARROT_CANNOT_RETURN_NULL
-static void*
+static void *
+get_free_list_item(ARGMOD(Pool_Allocator *pool))
+{
+    Pool_Allocator_Free_List * const item = pool->free_list;
+    pool->free_list = item->next;
+    return item;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static void *
+get_newfree_list_item(ARGMOD(Pool_Allocator *pool))
+{
+    Pool_Allocator_Free_List * const item = pool->newfree;
+    pool->newfree = (Pool_Allocator_Free_List *)
+                    ((char *)(pool->newfree) + pool->object_size);
+
+    if (pool->newfree >= pool->newlast)
+        pool->newfree = NULL;
+
+    return item;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static void *
 pool_allocate(ARGMOD(Pool_Allocator *pool))
 {
     ASSERT_ARGS(pool_allocate)
     Pool_Allocator_Free_List *item;
 
-    if (pool->free_list) {
-        item            = pool->free_list;
-        pool->free_list = item->next;
-    }
-    else if (pool->newfree) {
-        item          = pool->newfree;
-        pool->newfree = (Pool_Allocator_Free_List *)
-                        ((char *)(pool->newfree) + pool->object_size);
-        if (pool->newfree >= pool->newlast)
-            pool->newfree = NULL;
-    }
+    if (pool->free_list)
+        item = get_free_list_item(pool);
+
+    else if (pool->newfree)
+        item = get_newfree_list_item(pool);
+
     else {
         allocate_new_pool_arena(pool);
-        return pool_allocate(pool);
+        item = get_newfree_list_item(pool);
     }
 
     --pool->num_free_objects;
@@ -425,4 +465,3 @@
  * End:
  * vim: expandtab shiftwidth=4:
  */
-


More information about the parrot-commits mailing list