summaryrefslogtreecommitdiff
path: root/jsmn.c
diff options
context:
space:
mode:
authorSerge A. Zaitsev <devnull@localhost>2012-09-23 20:29:48 +0300
committerSerge A. Zaitsev <devnull@localhost>2012-09-23 20:29:48 +0300
commit974133db8531c7edd9969c8ebb04470318fc767d (patch)
treeadb0e48870c4834d7d5eb104c34060745290f152 /jsmn.c
parente542dea54ef194c36d5815bfe18a1b7e0615d02b (diff)
tokens array items are now being initialized during allocation, removed redundant code that significantly slowed down the parser
Diffstat (limited to 'jsmn.c')
-rw-r--r--jsmn.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/jsmn.c b/jsmn.c
index 761a60468..9a96c4fc4 100644
--- a/jsmn.c
+++ b/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;