mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-05 18:05:42 +02:00
Buffer the next character internally to make reading faster
This commit is contained in:
+22
-11
@@ -16,10 +16,21 @@ json_pull *json_begin(int (*read)(struct json_pull *), int (*peek)(struct json_p
|
|||||||
j->read = read;
|
j->read = read;
|
||||||
j->peek = peek;
|
j->peek = peek;
|
||||||
j->source = source;
|
j->source = source;
|
||||||
|
j->peeked = j->read(j);
|
||||||
|
|
||||||
return 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) {
|
static int read_file(json_pull *j) {
|
||||||
return fgetc(j->source);
|
return fgetc(j->source);
|
||||||
}
|
}
|
||||||
@@ -60,8 +71,8 @@ void json_end(json_pull *p) {
|
|||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_wrap(json_pull *j) {
|
static inline int read_wrap(json_pull *j) {
|
||||||
int c = j->read(j);
|
int c = next(j);
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
j->line++;
|
j->line++;
|
||||||
@@ -372,34 +383,34 @@ again:
|
|||||||
string_append(&val, c);
|
string_append(&val, c);
|
||||||
} else if (c >= '1' && c <= '9') {
|
} else if (c >= '1' && c <= '9') {
|
||||||
string_append(&val, c);
|
string_append(&val, c);
|
||||||
c = j->peek(j);
|
c = peek(j);
|
||||||
|
|
||||||
while (c >= '0' && c <= '9') {
|
while (c >= '0' && c <= '9') {
|
||||||
string_append(&val, read_wrap(j));
|
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));
|
string_append(&val, read_wrap(j));
|
||||||
|
|
||||||
c = j->peek(j);
|
c = peek(j);
|
||||||
while (c >= '0' && c <= '9') {
|
while (c >= '0' && c <= '9') {
|
||||||
string_append(&val, read_wrap(j));
|
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') {
|
if (c == 'e' || c == 'E') {
|
||||||
string_append(&val, read_wrap(j));
|
string_append(&val, read_wrap(j));
|
||||||
|
|
||||||
c = j->peek(j);
|
c = peek(j);
|
||||||
if (c == '+' || c == '-') {
|
if (c == '+' || c == '-') {
|
||||||
string_append(&val, read_wrap(j));
|
string_append(&val, read_wrap(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
c = j->peek(j);
|
c = peek(j);
|
||||||
if (c < '0' || c > '9') {
|
if (c < '0' || c > '9') {
|
||||||
j->error = "Exponent without digits";
|
j->error = "Exponent without digits";
|
||||||
string_free(&val);
|
string_free(&val);
|
||||||
@@ -407,7 +418,7 @@ again:
|
|||||||
}
|
}
|
||||||
while (c >= '0' && c <= '9') {
|
while (c >= '0' && c <= '9') {
|
||||||
string_append(&val, read_wrap(j));
|
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 (*read)(struct json_pull *);
|
||||||
int (*peek)(struct json_pull *);
|
int (*peek)(struct json_pull *);
|
||||||
|
int peeked;
|
||||||
void *source;
|
void *source;
|
||||||
|
|
||||||
json_object *container;
|
json_object *container;
|
||||||
|
|||||||
Reference in New Issue
Block a user