aboutsummaryrefslogtreecommitdiff
path: root/src/value.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/value.c
parentc9dddfa463d25f3af4dee5d20fe3eaeb23aed567 (diff)
added memory pool to reduce allocations 5x
Diffstat (limited to 'src/value.c')
-rw-r--r--src/value.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/value.c b/src/value.c
index 9a7f9b6..0d263d7 100644
--- a/src/value.c
+++ b/src/value.c
@@ -5,6 +5,12 @@
#include "value.h"
#include "lexer.h"
+#include "mempool.h"
+
+#define MEMPOOL_OBJ_TYPE struct value
+#define MEMPOOL_CAP 64
+MEMPOOL_GENERATE(value)
+
#define NOT_IMPLEMENTED() die("Not Implemented. ABORTING")
const char * const value_type_string[] = {
@@ -76,7 +82,8 @@ static void proc_destroy(struct proc *proc);
value_t value_create(enum value_type type, void *value)
{
- value_t _value = malloc(sizeof(*_value));
+ // value_t _value = malloc(sizeof(*_value));
+ value_t _value = value_mempool_allocate();
_value->type = type;
switch(type) {
@@ -98,7 +105,8 @@ void value_destroy(value_t value)
}
if(value->refs == 0)
- free(value);
+ value_mempool_free(value);
+ // free(value);
}
value_t value_from_token(struct token *token)