From 9dfb56a435743bd5af2e8ec452c60eee50a2049b Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Fri, 29 Jul 2005 15:25:20 +0000 Subject: [PATCH] keep a tail pointer. Speeds up the benchmark by about 50%. 2005-07-29 Sven Neumann * app/base/siox.c (add_to_list): keep a tail pointer. Speeds up the benchmark by about 50%. --- app/base/siox.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/app/base/siox.c b/app/base/siox.c index decc566243..6bd003a1b2 100644 --- a/app/base/siox.c +++ b/app/base/siox.c @@ -64,7 +64,10 @@ /* Simulate a java.util.ArrayList */ -/* These methods are NOT generic */ + +/* Could be improved. At the moment we are wasting a node per list and + * the tail pointer on each node is only used in the first node. + */ typedef struct { @@ -82,29 +85,32 @@ struct _ArrayList guint arraylength; gboolean owned; ArrayList *next; + ArrayList *tail; /* only valid in the root item */ }; +static ArrayList * +list_new (void) +{ + ArrayList *list = g_new0 (ArrayList, 1); + + list->tail = list; + + return list; +} + static void add_to_list (ArrayList *list, lab *array, guint arraylength, gboolean take) { - ArrayList *cur = list; - ArrayList *prev; + ArrayList *tail = list->tail; - do - { - prev = cur; - cur = cur->next; - } - while (cur); + tail->array = array; + tail->arraylength = arraylength; + tail->owned = take; - prev->next = g_new0 (ArrayList, 1); - - prev->array = array; - prev->arraylength = arraylength; - prev->owned = take; + list->tail = tail->next = g_new0 (ArrayList, 1); } static int @@ -510,7 +516,7 @@ create_signature (lab *input, return NULL; } - clusters1 = g_new0 (ArrayList, 1); + clusters1 = list_new (); stageone (input, SIOX_DIMS, 0, clusters1, limits, length); clusters1size = list_size (clusters1); @@ -545,7 +551,7 @@ create_signature (lab *input, g_printerr ("step #1 -> %d clusters\n", clusters1size); #endif - clusters2 = g_new0 (ArrayList, 1); + clusters2 = list_new (); stagetwo (centroids, SIOX_DIMS, 0, clusters2, limits, clusters1size, length,