From 2b2ddbdb94334d586cab8e4737062bb2e794d102 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Tue, 17 Mar 2020 13:47:10 +0100 Subject: re-use parser between template() calls --- src/template.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/template.c b/src/template.c index 9343ec1..1f6a34f 100644 --- a/src/template.c +++ b/src/template.c @@ -256,6 +256,11 @@ int eval(char *dest, mpc_ast_t* t, struct hashmap *ctx) { } mpc_parser_t *parser_init() { + static mpc_parser_t *template; + if (template != NULL) { + return template; + } + mpc_parser_t *symbol = mpc_new("symbol"); mpc_parser_t *number = mpc_new("number"); mpc_parser_t *string = mpc_new("string"); @@ -273,7 +278,7 @@ mpc_parser_t *parser_init() { mpc_parser_t *statement_extends = mpc_new("extends"); mpc_parser_t *body = mpc_new("body"); mpc_parser_t *content = mpc_new("content"); - mpc_parser_t *template = mpc_new("template"); + template = mpc_new("template"); mpca_lang(MPCA_LANG_DEFAULT, " symbol : /[a-zA-Z][a-zA-Z0-9_.]*/ ;" " number : /[0-9]+/ ;" -- cgit v1.2.3