From 127adf4036baa5d6c41d59b4e2b3462b4180c2d6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 7 Jul 2009 16:59:08 -0700 Subject: More work on the benchmark. --- upb_parse.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'upb_parse.c') diff --git a/upb_parse.c b/upb_parse.c index 3195e71..dcad9c9 100644 --- a/upb_parse.c +++ b/upb_parse.c @@ -253,17 +253,23 @@ upb_status_t upb_parse_value(void **buf, void *end, upb_field_type_t ft, #undef CASE } -void upb_parse_init(struct upb_parse_state *state, size_t udata_size) +void upb_parse_reset(struct upb_parse_state *state) { - memset(state, 0, sizeof(struct upb_parse_state)); state->offset = 0; - size_t stack_bytes = (sizeof(*state->stack) + udata_size) * UPB_MAX_NESTING; - state->stack = state->top = malloc(stack_bytes); + state->top = state->stack; /* The top-level message is not delimited (we can keep receiving data for * it indefinitely). */ state->top->end_offset = SIZE_MAX; +} + +void upb_parse_init(struct upb_parse_state *state, size_t udata_size) +{ + memset(state, 0, sizeof(struct upb_parse_state)); /* Clear all callbacks. */ + size_t stack_bytes = (sizeof(*state->stack) + udata_size) * UPB_MAX_NESTING; + state->stack = malloc(stack_bytes); state->limit = (struct upb_parse_stack_frame*)((char*)state->stack + stack_bytes); state->udata_size = udata_size; + upb_parse_reset(state); } void upb_parse_free(struct upb_parse_state *state) -- cgit v1.2.3