From 721528ed9320ecc4e9249ca36a378e5cdab2a4d1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Milo=C5=A1=20Mula=C4=8D?= Date: Fri, 6 Jun 2008 13:53:48 +0000 Subject: [PATCH] - some of 'quatraticism' removed (speed up especially for big dumps containing 10k jobs and more) - faster dump_storage element lookup --- org.glite.lb.utils/src/dump_exporter.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/org.glite.lb.utils/src/dump_exporter.c b/org.glite.lb.utils/src/dump_exporter.c index 68b87e1..db89c48 100644 --- a/org.glite.lb.utils/src/dump_exporter.c +++ b/org.glite.lb.utils/src/dump_exporter.c @@ -24,6 +24,7 @@ #define KEYNAME_JOBID "jobid " #define KEYNAME_FILE "file " #define KEYNAME_JPPS "jpps " +#define REALLOC_CHUNK 10000 typedef struct _buffer_t { char *str; @@ -262,14 +263,20 @@ cleanup_lbl: return (ret); } - +/* look thru list from the last element to the first + * last element is most likely corresponding to the job we are looking for + */ static dump_storage_t *dump_storage_find(dump_storage_t *st, char *job) { - while ( st && st->job ) { - if ( !strcmp(job, st->job) ) break; - st++; + int i; + + st = st + (number_of_st -1); // point to the last element + + for (i=number_of_st; i > 0; i--) { + if (!st || !st->job) return NULL; + if ( !strcmp(job, st->job) ) return st; + st--; } - if ( st && st->job ) return st; return NULL; } @@ -277,11 +284,12 @@ static dump_storage_t *dump_storage_add(dump_storage_t **st, char *job, char *fn { dump_storage_t *tmp; - if ( number_of_st ) tmp = realloc(*st, (number_of_st+2)*sizeof(*tmp)); - else tmp = calloc(2, sizeof(*tmp)); - if ( !tmp ) return NULL; + if ( !(number_of_st % REALLOC_CHUNK) ) { + *st = realloc(*st, (REALLOC_CHUNK + number_of_st+2)*sizeof(*tmp)); + printf("reallocing\n"); + } + if ( !(*st) ) return NULL; - *st = tmp; tmp = *st + number_of_st; if ( !(tmp->job = strdup(job)) ) return NULL; -- 1.8.2.3