Save a few more bytes per geometry in the temporary file

by using bytes instead of ints for the drawing operations
This commit is contained in:
Eric Fischer
2014-11-05 14:37:54 -08:00
parent c24cfada61
commit 241d96e57c
4 changed files with 16 additions and 5 deletions
+13 -3
View File
@@ -96,6 +96,11 @@ void serialize_int(FILE *out, int n, long long *fpos, char *fname, json_pull *so
*fpos += sizeof(int); *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) { void serialize_uint(FILE *out, unsigned n, long long *fpos, char *fname, json_pull *source) {
fwrite_check(&n, sizeof(unsigned), 1, out, fname, source); fwrite_check(&n, sizeof(unsigned), 1, out, fname, source);
*fpos += sizeof(unsigned); *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, x, fpos, fname, source);
serialize_uint(out, y, fpos, fname, source); serialize_uint(out, y, fpos, fname, source);
} else { } else {
@@ -163,7 +168,7 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE
if (t == GEOM_POLYGON) { if (t == GEOM_POLYGON) {
if (*fpos != began) { 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); *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 *deserialize_string(char **f, struct pool *p, int type) {
struct pool_val *ret; struct pool_val *ret;
int len; 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 }; unsigned bbox[] = { UINT_MAX, UINT_MAX, 0, 0 };
parse_geometry(t, coordinates, bbox, &fpos, metafile, VT_MOVETO, fname, jp); 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 *metakey[properties->length];
char *metaval[properties->length]; char *metaval[properties->length];
+1 -1
View File
@@ -22,7 +22,7 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail
while (1) { while (1) {
draw d; draw d;
deserialize_int(meta, &d.op); deserialize_byte(meta, &d.op);
if (d.op == VT_END) { if (d.op == VT_END) {
break; break;
} }
+1 -1
View File
@@ -1,5 +1,5 @@
struct draw { struct draw {
int op; signed char op;
long long x; long long x;
long long y; long long y;
int necessary; int necessary;
+1
View File
@@ -14,6 +14,7 @@
struct pool; struct pool;
void deserialize_int(char **f, int *n); 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); struct pool_val *deserialize_string(char **f, struct pool *p, int type);