Permalink
Browse files

Merge pull request #20 from snej/fast_reset

Optimized jsonsl_reset by removing code to reinitialize the stack
  • Loading branch information...
2 parents 57f93ed + c6a296b commit e21dd0a910eba47be4bc2cd2d824e62af8ccddec @mnunberg committed on GitHub Sep 29, 2016
Showing with 4 additions and 7 deletions.
  1. +4 −7 jsonsl.c
View
@@ -101,6 +101,7 @@ static char get_escape_equiv(unsigned);
JSONSL_API
jsonsl_t jsonsl_new(int nlevels)
{
+ unsigned int ii;
struct jsonsl_st *jsn = (struct jsonsl_st *)
calloc(1, sizeof (*jsn) +
( (nlevels-1) * sizeof (struct jsonsl_state_st) )
@@ -109,26 +110,22 @@ jsonsl_t jsonsl_new(int nlevels)
jsn->levels_max = nlevels;
jsn->max_callback_level = -1;
jsonsl_reset(jsn);
+ for (ii = 0; ii < jsn->levels_max; ii++) {
+ jsn->stack[ii].level = ii;
+ }
return jsn;
}
JSONSL_API
void jsonsl_reset(jsonsl_t jsn)
{
- unsigned int ii;
jsn->tok_last = 0;
jsn->can_insert = 1;
jsn->pos = 0;
jsn->level = 0;
jsn->stopfl = 0;
jsn->in_escape = 0;
jsn->expecting = 0;
-
- memset(jsn->stack, 0, (jsn->levels_max * sizeof (struct jsonsl_state_st)));
-
- for (ii = 0; ii < jsn->levels_max; ii++) {
- jsn->stack[ii].level = ii;
- }
}
JSONSL_API

0 comments on commit e21dd0a

Please sign in to comment.