Anonymous avatar Anonymous committed b4737a8

tokens array items are now being initialized during allocation, removed redundant code that significantly slowed down the parser

Comments (0)

Files changed (2)

  */
 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;
 }
 
 /**
 	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;
 	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);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.