From: Miloš Mulač Date: Thu, 23 Aug 2007 13:18:25 +0000 (+0000) Subject: speedup (removed quadratic algorithm) X-Git-Tag: glite-lb-client_R_3_0_1_1~28 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=0de32dbe5aebace28b6afd81cf5eea6c2a13313a;p=jra1mw.git speedup (removed quadratic algorithm) --- diff --git a/org.glite.lb.client/src/lb_dump_exporter.c b/org.glite.lb.client/src/lb_dump_exporter.c index e4d4f1c..4592412 100644 --- a/org.glite.lb.client/src/lb_dump_exporter.c +++ b/org.glite.lb.client/src/lb_dump_exporter.c @@ -38,6 +38,9 @@ typedef struct _dump_storage_t { int fhnd; } dump_storage_t; +/* hold actual number of records in dump_storage_t structure st (defined below) */ +int number_of_st = 0; + static const char *optstr = "d:s:j:m:h"; static struct option opts[] = { @@ -264,19 +267,18 @@ static dump_storage_t *dump_storage_find(dump_storage_t *st, char *job) static dump_storage_t *dump_storage_add(dump_storage_t **st, char *job, char *fname, int fhnd) { dump_storage_t *tmp; - int ct; - for ( ct = 0, tmp = *st; tmp && tmp->job; ct++, tmp++ ) ; - if ( ct ) tmp = realloc(*st, (ct+2)*sizeof(*tmp)); + if ( number_of_st ) tmp = realloc(*st, (number_of_st+2)*sizeof(*tmp)); else tmp = calloc(2, sizeof(*tmp)); if ( !tmp ) return NULL; *st = tmp; - while ( tmp && tmp->job ) tmp++; - + tmp = *st + number_of_st; + if ( !(tmp->job = strdup(job)) ) return NULL; - if ( !(tmp->fname = strdup(fname)) ) { free(tmp->job); return NULL; } + if ( !(tmp->fname = strdup(fname)) ) { free(tmp->job); (tmp)->job = NULL; return NULL; } tmp->fhnd = fhnd; + number_of_st++; (tmp+1)->job = NULL; return tmp;