mirror of
https://github.com/optim-enterprises-bv/nDPId.git
synced 2026-01-11 17:45:19 +00:00
tokens array items are now being initialized during allocation, removed redundant code that significantly slowed down the parser
This commit is contained in:
19
jsmn.c
19
jsmn.c
@@ -7,14 +7,14 @@
|
||||
*/
|
||||
static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
|
||||
jsmntok_t *tokens, size_t num_tokens) {
|
||||
unsigned int i;
|
||||
for (i = parser->toknext; i < num_tokens; i++) {
|
||||
if (tokens[i].start == -1 && tokens[i].end == -1) {
|
||||
parser->toknext = i + 1;
|
||||
return &tokens[i];
|
||||
}
|
||||
jsmntok_t *tok;
|
||||
if (parser->toknext >= num_tokens) {
|
||||
return NULL;
|
||||
}
|
||||
return NULL;
|
||||
tok = &tokens[parser->toknext++];
|
||||
tok->start = tok->end = -1;
|
||||
tok->size = 0;
|
||||
return tok;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,11 +128,6 @@ jsmnerr_t jsmn_parse(jsmn_parser *parser, const char *js, jsmntok_t *tokens,
|
||||
unsigned int tokindex;
|
||||
jsmntok_t *token;
|
||||
|
||||
/* initialize the rest of tokens (they could be reallocated) */
|
||||
for (tokindex = parser->toknext; tokindex < num_tokens; tokindex++) {
|
||||
jsmn_fill_token(&tokens[tokindex], JSMN_PRIMITIVE, -1, -1);
|
||||
}
|
||||
|
||||
for (; js[parser->pos] != '\0'; parser->pos++) {
|
||||
char c;
|
||||
jsmntype_t type;
|
||||
|
||||
@@ -156,13 +156,13 @@ int test_partial_string() {
|
||||
r = jsmn_parse(&p, js, tok, 10);
|
||||
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_STRING);
|
||||
check(TOKEN_STRING(js, tok[0], "x"));
|
||||
check(TOKEN_EQ(tok[1], -1, -1, 0));
|
||||
check(p.toknext == 1);
|
||||
|
||||
js = "\"x\": \"valu";
|
||||
r = jsmn_parse(&p, js, tok, 10);
|
||||
check(r == JSMN_ERROR_PART && tok[0].type == JSMN_STRING);
|
||||
check(TOKEN_STRING(js, tok[0], "x"));
|
||||
check(TOKEN_EQ(tok[1], -1, -1, 0));
|
||||
check(p.toknext == 1);
|
||||
|
||||
js = "\"x\": \"value\"";
|
||||
r = jsmn_parse(&p, js, tok, 10);
|
||||
|
||||
Reference in New Issue
Block a user