From: Miloš Mulač Date: Fri, 6 Jun 2008 13:53:48 +0000 (+0000) Subject: - some of 'quatraticism' removed (speed up especially for big dumps containing 10k... X-Git-Tag: glite-yaim-lb_R_4_0_3_1~6 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=721528ed9320ecc4e9249ca36a378e5cdab2a4d1;p=jra1mw.git - some of 'quatraticism' removed (speed up especially for big dumps containing 10k jobs and more) - faster dump_storage element lookup --- 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;