Stop duplicating pool initialization code

This commit is contained in:
Eric Fischer 2014-09-29 12:12:54 -07:00
parent 5ab7f89465
commit fabeb4588d
3 changed files with 14 additions and 29 deletions

@ -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:

21
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;

1
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 {