From fabeb4588d0e2f0c733860fa5b6197e4da72c74d Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 29 Sep 2014 12:12:54 -0700 Subject: [PATCH] Stop duplicating pool initialization code --- geojson.c | 21 +++++++++------------ tile.cc | 21 ++++----------------- tile.h | 1 + 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/geojson.c b/geojson.c index 3db89e4..02212a6 100644 --- a/geojson.c +++ b/geojson.c @@ -227,6 +227,12 @@ void pool_free(struct pool *p) { p->vals = NULL; } +void pool_init(struct pool *p, int n) { + p->n = n; + p->vals = NULL; + p->head = NULL; + p->tail = NULL; +} size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream) { size_t w = fwrite(ptr, size, nitems, stream); @@ -629,10 +635,7 @@ next_feature: } struct pool file_keys; - file_keys.n = 0; - file_keys.vals = NULL; - file_keys.head = NULL; - file_keys.tail = NULL; + pool_init(&file_keys, 0); char trunc[strlen(fname) + 1]; if (layername == NULL) { @@ -790,10 +793,7 @@ int main(int argc, char **argv) { int minzoom = 0; struct pool exclude; - exclude.n = 0; - exclude.vals = NULL; - exclude.head = NULL; - exclude.tail = NULL; + pool_init(&exclude, 0); while ((i = getopt(argc, argv, "l:n:z:Z:d:D:o:x:")) != -1) { switch (i) { @@ -826,10 +826,7 @@ int main(int argc, char **argv) { break; case 'x': - { - struct pool_val *pv = pool(&exclude, optarg, VT_STRING); - pv->n = 1; - } + pool(&exclude, optarg, VT_STRING); break; default: diff --git a/tile.cc b/tile.cc index b587e58..cc74564 100644 --- a/tile.cc +++ b/tile.cc @@ -445,23 +445,10 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns layer->set_extent(1 << detail); - struct pool keys; - keys.n = 0; - keys.vals = NULL; - keys.head = NULL; - keys.tail = NULL; - - struct pool values; - values.n = 0; - values.vals = NULL; - values.head = NULL; - values.tail = NULL; - - struct pool dup; - dup.n = 1; - dup.vals = NULL; - dup.head = NULL; - dup.tail = NULL; + struct pool keys, values, dup; + pool_init(&keys, 0); + pool_init(&values, 0); + pool_init(&dup, 1); double interval = 1; double seq = 0; diff --git a/tile.h b/tile.h index fbfddb4..e0eb8ad 100644 --- a/tile.h +++ b/tile.h @@ -39,6 +39,7 @@ struct pool_val *deserialize_string(char **f, struct pool *p, int type); struct pool_val *pool(struct pool *p, char *s, int type); struct pool_val *pool_long_long(struct pool *p, long long *val, int type); void pool_free(struct pool *p); +void pool_init(struct pool *p, int n); struct index {