aboutsummaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-09-03 00:48:18 +0300
committerkartofen <mladenovnasko0@gmail.com>2024-09-03 00:48:18 +0300
commitdb32849ce314a93db01f877a057a91022fec7c8b (patch)
tree07b35b25a49edf9d92ece9cc3ebce2419f7971e3 /src/env.c
parentc9dddfa463d25f3af4dee5d20fe3eaeb23aed567 (diff)
added memory pool to reduce allocations 5x
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c14
1 files changed, 11 insertions, 3 deletions
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)