aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-17 13:47:10 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-17 13:47:10 +0100
commit2b2ddbdb94334d586cab8e4737062bb2e794d102 (patch)
treef6425fcba9e587feb47e2095bc3507c2ac5e8318
parent8857b9d1490646750f9b9c5a464058f4a3ac9987 (diff)
downloadunja-2b2ddbdb94334d586cab8e4737062bb2e794d102.tar.gz
unja-2b2ddbdb94334d586cab8e4737062bb2e794d102.zip
re-use parser between template() calls
-rw-r--r--src/template.c7
1 files changed, 6 insertions, 1 deletions
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]+/ ;"