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
+9 -12
View File
@@ -227,6 +227,12 @@ void pool_free(struct pool *p) {
p->vals = NULL; 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 fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream) {
size_t w = fwrite(ptr, size, nitems, stream); size_t w = fwrite(ptr, size, nitems, stream);
@@ -629,10 +635,7 @@ next_feature:
} }
struct pool file_keys; struct pool file_keys;
file_keys.n = 0; pool_init(&file_keys, 0);
file_keys.vals = NULL;
file_keys.head = NULL;
file_keys.tail = NULL;
char trunc[strlen(fname) + 1]; char trunc[strlen(fname) + 1];
if (layername == NULL) { if (layername == NULL) {
@@ -790,10 +793,7 @@ int main(int argc, char **argv) {
int minzoom = 0; int minzoom = 0;
struct pool exclude; struct pool exclude;
exclude.n = 0; pool_init(&exclude, 0);
exclude.vals = NULL;
exclude.head = NULL;
exclude.tail = NULL;
while ((i = getopt(argc, argv, "l:n:z:Z:d:D:o:x:")) != -1) { while ((i = getopt(argc, argv, "l:n:z:Z:d:D:o:x:")) != -1) {
switch (i) { switch (i) {
@@ -826,10 +826,7 @@ int main(int argc, char **argv) {
break; break;
case 'x': case 'x':
{ pool(&exclude, optarg, VT_STRING);
struct pool_val *pv = pool(&exclude, optarg, VT_STRING);
pv->n = 1;
}
break; break;
default: default:
+4 -17
View File
@@ -445,23 +445,10 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns
layer->set_extent(1 << detail); layer->set_extent(1 << detail);
struct pool keys; struct pool keys, values, dup;
keys.n = 0; pool_init(&keys, 0);
keys.vals = NULL; pool_init(&values, 0);
keys.head = NULL; pool_init(&dup, 1);
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;
double interval = 1; double interval = 1;
double seq = 0; double seq = 0;
+1
View File
@@ -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(struct pool *p, char *s, int type);
struct pool_val *pool_long_long(struct pool *p, long long *val, int type); struct pool_val *pool_long_long(struct pool *p, long long *val, int type);
void pool_free(struct pool *p); void pool_free(struct pool *p);
void pool_init(struct pool *p, int n);
struct index { struct index {