From 241d96e57c965f454410f4b36b05c28184170f65 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 5 Nov 2014 14:37:54 -0800 Subject: [PATCH] Save a few more bytes per geometry in the temporary file by using bytes instead of ints for the drawing operations --- geojson.c | 16 +++++++++++++--- geometry.cc | 2 +- geometry.hh | 2 +- tile.h | 1 + 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/geojson.c b/geojson.c index 3f15c15..ff498f6 100644 --- a/geojson.c +++ b/geojson.c @@ -96,6 +96,11 @@ void serialize_int(FILE *out, int n, long long *fpos, char *fname, json_pull *so *fpos += sizeof(int); } +void serialize_byte(FILE *out, signed char n, long long *fpos, char *fname, json_pull *source) { + fwrite_check(&n, sizeof(signed char), 1, out, fname, source); + *fpos += sizeof(signed char); +} + void serialize_uint(FILE *out, unsigned n, long long *fpos, char *fname, json_pull *source) { fwrite_check(&n, sizeof(unsigned), 1, out, fname, source); *fpos += sizeof(unsigned); @@ -153,7 +158,7 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE } } - serialize_int(out, op, fpos, fname, source); + serialize_byte(out, op, fpos, fname, source); serialize_uint(out, x, fpos, fname, source); serialize_uint(out, y, fpos, fname, source); } else { @@ -163,7 +168,7 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE if (t == GEOM_POLYGON) { if (*fpos != began) { - serialize_int(out, VT_CLOSEPATH, fpos, fname, source); + serialize_byte(out, VT_CLOSEPATH, fpos, fname, source); } } } @@ -173,6 +178,11 @@ void deserialize_int(char **f, int *n) { *f += sizeof(int); } +void deserialize_byte(char **f, signed char *n) { + memcpy(n, *f, sizeof(signed char)); + *f += sizeof(signed char); +} + struct pool_val *deserialize_string(char **f, struct pool *p, int type) { struct pool_val *ret; int len; @@ -382,7 +392,7 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, unsigned bbox[] = { UINT_MAX, UINT_MAX, 0, 0 }; parse_geometry(t, coordinates, bbox, &fpos, metafile, VT_MOVETO, fname, jp); - serialize_int(metafile, VT_END, &fpos, fname, jp); + serialize_byte(metafile, VT_END, &fpos, fname, jp); char *metakey[properties->length]; char *metaval[properties->length]; diff --git a/geometry.cc b/geometry.cc index 31eef53..5425d94 100644 --- a/geometry.cc +++ b/geometry.cc @@ -22,7 +22,7 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail while (1) { draw d; - deserialize_int(meta, &d.op); + deserialize_byte(meta, &d.op); if (d.op == VT_END) { break; } diff --git a/geometry.hh b/geometry.hh index b21bb99..7af9b4e 100644 --- a/geometry.hh +++ b/geometry.hh @@ -1,5 +1,5 @@ struct draw { - int op; + signed char op; long long x; long long y; int necessary; diff --git a/tile.h b/tile.h index 9b29f8b..2141590 100644 --- a/tile.h +++ b/tile.h @@ -14,6 +14,7 @@ struct pool; void deserialize_int(char **f, int *n); +void deserialize_byte(char **f, signed char *n); struct pool_val *deserialize_string(char **f, struct pool *p, int type);