From db32849ce314a93db01f877a057a91022fec7c8b Mon Sep 17 00:00:00 2001 From: kartofen Date: Tue, 3 Sep 2024 00:48:18 +0300 Subject: added memory pool to reduce allocations 5x --- src/env.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index 10aa651..35b2ddf 100644 --- a/src/env.c +++ b/src/env.c @@ -5,7 +5,13 @@ #include "env.h" #include "value.h" -#define ENV_TABLE_CAP (1 << 8) +#include "mempool.h" + +#define MEMPOOL_OBJ_TYPE struct symbol_table +#define MEMPOOL_CAP 64 +MEMPOOL_GENERATE(env) + +#define ENV_TABLE_CAP (1 << 3) static unsigned long str_hash(char *str) { @@ -34,7 +40,8 @@ static bool equal(void *key1, void *key2) env_t env_create(env_t parent, env_destroy_func destroy_func) { - env_t env = malloc(sizeof(*env)); + // env_t env = malloc(sizeof(*env)); + env_t env = env_mempool_allocate(); env->destroy_func = destroy_func; env->parent = parent; env->refs = 1; @@ -59,7 +66,8 @@ void env_destroy(env_t env) } hashtable_destroy(env->table); - free(env); + // free(env); + env_mempool_free(env); } env_t env_copy(env_t env) -- cgit v1.2.3