Segment the file into input chunks. Allow commas at the top level.

This commit is contained in:
Eric Fischer
2015-12-18 15:59:07 -08:00
parent ed90c7b53a
commit 2159d464d0
2 changed files with 32 additions and 17 deletions
+19 -1
View File
@@ -903,10 +903,28 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
} }
if (map != NULL && map != MAP_FAILED) { if (map != NULL && map != MAP_FAILED) {
jp = json_begin_map(map, st.st_size - off); #define THREADS 10
long long segs[THREADS + 1];
segs[0] = 0;
segs[THREADS] = st.st_size - off;
int i;
for (i = 1; i < THREADS; i++) {
segs[i] = off + (st.st_size - off) * i / THREADS;
while (segs[i] < st.st_size && map[segs[i]] != '\n') {
segs[i]++;
}
printf("%d %lld\n", i, segs[i]);
}
for (i = 0; i < THREADS; i++) {
jp = json_begin_map(map + segs[i], segs[i + 1] - segs[i]);
parse_json(jp, reading, &seq, &metapos, &geompos, &indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, maxzoom, basezoom, source, droprate, file_bbox); parse_json(jp, reading, &seq, &metapos, &geompos, &indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, maxzoom, basezoom, source, droprate, file_bbox);
free(jp->source); free(jp->source);
json_end(jp); json_end(jp);
}
} else { } else {
FILE *fp = fdopen(fd, "r"); FILE *fp = fdopen(fd, "r");
if (fp == NULL) { if (fp == NULL) {
+2 -5
View File
@@ -332,11 +332,7 @@ again:
/////////////////////////// Comma /////////////////////////// Comma
if (c == ',') { if (c == ',') {
if (j->container == NULL) { if (j->container != NULL) {
j->error = "Found comma at top level";
return NULL;
}
if (j->container->expect != JSON_COMMA) { if (j->container->expect != JSON_COMMA) {
j->error = "Found unexpected comma"; j->error = "Found unexpected comma";
return NULL; return NULL;
@@ -347,6 +343,7 @@ again:
} else { } else {
j->container->expect = JSON_ITEM; j->container->expect = JSON_ITEM;
} }
}
if (cb != NULL) { if (cb != NULL) {
cb(JSON_COMMA, j, state); cb(JSON_COMMA, j, state);