mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-23 10:30:16 +00:00
Buffer the next character internally to make reading faster
This commit is contained in:
parent
043b35eede
commit
84b9dea51e
33
jsonpull.c
33
jsonpull.c
@ -16,10 +16,21 @@ json_pull *json_begin(int (*read)(struct json_pull *), int (*peek)(struct json_p
|
||||
j->read = read;
|
||||
j->peek = peek;
|
||||
j->source = source;
|
||||
j->peeked = j->read(j);
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
static inline int peek(json_pull *j) {
|
||||
return j->peeked;
|
||||
}
|
||||
|
||||
static inline int next(json_pull *j) {
|
||||
int ret = j->peeked;
|
||||
j->peeked = j->read(j);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int read_file(json_pull *j) {
|
||||
return fgetc(j->source);
|
||||
}
|
||||
@ -60,8 +71,8 @@ void json_end(json_pull *p) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
static int read_wrap(json_pull *j) {
|
||||
int c = j->read(j);
|
||||
static inline int read_wrap(json_pull *j) {
|
||||
int c = next(j);
|
||||
|
||||
if (c == '\n') {
|
||||
j->line++;
|
||||
@ -372,34 +383,34 @@ again:
|
||||
string_append(&val, c);
|
||||
} else if (c >= '1' && c <= '9') {
|
||||
string_append(&val, c);
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
|
||||
while (c >= '0' && c <= '9') {
|
||||
string_append(&val, read_wrap(j));
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
}
|
||||
}
|
||||
|
||||
if (j->peek(j) == '.') {
|
||||
if (peek(j) == '.') {
|
||||
string_append(&val, read_wrap(j));
|
||||
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
while (c >= '0' && c <= '9') {
|
||||
string_append(&val, read_wrap(j));
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
}
|
||||
}
|
||||
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
if (c == 'e' || c == 'E') {
|
||||
string_append(&val, read_wrap(j));
|
||||
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
if (c == '+' || c == '-') {
|
||||
string_append(&val, read_wrap(j));
|
||||
}
|
||||
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
if (c < '0' || c > '9') {
|
||||
j->error = "Exponent without digits";
|
||||
string_free(&val);
|
||||
@ -407,7 +418,7 @@ again:
|
||||
}
|
||||
while (c >= '0' && c <= '9') {
|
||||
string_append(&val, read_wrap(j));
|
||||
c = j->peek(j);
|
||||
c = peek(j);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ typedef struct json_pull {
|
||||
|
||||
int (*read)(struct json_pull *);
|
||||
int (*peek)(struct json_pull *);
|
||||
int peeked;
|
||||
void *source;
|
||||
|
||||
json_object *container;
|
||||
|
Loading…
x
Reference in New Issue
Block a user