From dd5cc15a2b020de69992cc9996d8f52ea995acdd Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com> Date: Sun, 4 Oct 2015 17:07:59 +0200 Subject: [PATCH] shave off another ~500ns/iter by not initialising HLeftRecs we'll never use --- src/backends/packrat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/backends/packrat.c b/src/backends/packrat.c index abb198b0..f21e22ab 100644 --- a/src/backends/packrat.c +++ b/src/backends/packrat.c @@ -188,9 +188,10 @@ HParseResult* h_do_parse(const HParser* parser, HParseState *state) { // check to see if there is already a result for this object... if (!m) { // It doesn't exist, so create a dummy result to cache - HLeftRec *base = a_new(HLeftRec, 1); + HLeftRec *base = NULL; // But only cache it now if there's some chance it could grow; primitive parsers can't if (parser->vtable->higher) { + base = a_new(HLeftRec, 1); base->seed = NULL; base->rule = parser; base->head = NULL; h_slist_push(state->lr_stack, base); // cache it @@ -207,7 +208,7 @@ HParseResult* h_do_parse(const HParser* parser, HParseState *state) { cached->input_stream = state->input_stream; } // setupLR, used below, mutates the LR to have a head if appropriate, so we check to see if we have one - if (NULL == base->head) { + if (!base || NULL == base->head) { h_hashtable_put(state->cache, key, cached_result(state, tmp_res)); return tmp_res; } else { -- GitLab