diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/std/hash_map.h | 1 | ||||
-rw-r--r-- | src/ir/ir.c | 1 | ||||
-rw-r--r-- | src/std/file.c | 4 | ||||
-rw-r--r-- | src/std/hash_map.c | 11 |
5 files changed, 17 insertions, 2 deletions
@@ -68,6 +68,8 @@ All branch targets should be 16-byte aligned. ``` * Reduce the number of branches by making memory allocation/reallocation throw instead of returning error. * Implement pub for imports and show compile error when using non-pub symbols in pub closures/structs/etc. +* Use a list instead of a hash map for variable lookup, since the list will be small most of the time. +* Optimize buffer_append by returning pre-allocated space which can be used directly, instead of adding data to a variable and then copying it to the buffer. # Documents Documents are located under doc. The file doc/Documentation.md is generated from source files by running doc/doc_extract.py but there is no need to run this script unless you are modifying documentation in the source. diff --git a/include/std/hash_map.h b/include/std/hash_map.h index 05755ce..19f97a2 100644 --- a/include/std/hash_map.h +++ b/include/std/hash_map.h @@ -12,6 +12,7 @@ typedef struct HashMap HashMap; typedef int(*HashMapCompare)(const void *a, const void *b); typedef usize(*HashMapHash)(const u8 *data, usize size); +/* TODO: Optimize small hash maps by using the members of the struct instead of allocating on heap */ struct HashMap { ArenaAllocator *allocator; /* borrowed */ Buffer/*HashMapBucket*/ buckets; diff --git a/src/ir/ir.c b/src/ir/ir.c index 1ca154a..a6ed931 100644 --- a/src/ir/ir.c +++ b/src/ir/ir.c @@ -271,6 +271,7 @@ static CHECK_RESULT int ir_add_ins_form2(Ir *self, IrInstruction ins_type, IrReg ins_form_2.lhs = lhs; ins_form_2.rhs = rhs; amal_log_debug("r%d = r%d %s r%d", *result, lhs, binop_type_to_string(ins_type), rhs); + /* TODO: Store ins_type as an uint8_t instead of int */ return_if_error(buffer_append(&self->instructions, &ins_type, 1)); return buffer_append(&self->instructions, &ins_form_2, sizeof(ins_form_2)); } diff --git a/src/std/file.c b/src/std/file.c index 84f4b0c..3ca94b0 100644 --- a/src/std/file.c +++ b/src/std/file.c @@ -176,6 +176,10 @@ typedef enum { OTHER } FileType; +/* + TODO: Remove this and instead use fstat, and then read the file. + Otherwise this is not atomic and the file type can change between the calls +*/ static CHECK_RESULT int file_get_type(const char *filepath, FileType *type) { struct stat file_stats; if(stat(filepath, &file_stats) == -1) { diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 234f3e3..b4bd4c1 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -3,8 +3,13 @@ #include "../../include/std/mem.h" #include <assert.h> +/* Basic hash map implementation */ + /* -Basic hash map implementation. TODO: Improve performance + TODO: Improve performance. For example replace % with & by first making sure size of bucket is a power of two. + TODO: Instead of allocating space for the key, use the key data pointer and size directly. + TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert + method and use that directly. */ #define HASH_MAP_INITIAL_SIZE 8 @@ -109,6 +114,7 @@ static void hash_map_reorder_nodes(HashMap *self, usize end_index) { usize bucket_size; usize index; + /* TODO: bucket_end should be the old capacity. There is no need to reorder the new buckets */ bucket = (HashMapBucket*)self->buckets.data; bucket_end = ((HashMapBucket*)self->buckets.data) + end_index; bucket_size = buffer_get_size(&self->buckets, HashMapBucket); @@ -177,6 +183,7 @@ int hash_map_insert(HashMap *self, BufferView key, void *value) { return 0; } +/* TODO: Remove this. Use hash_map_get_ref instead */ bool hash_map_get(HashMap *self, BufferView key, void *value) { #if 0 usize bucket_size; @@ -235,7 +242,7 @@ bool hash_map_get_ref(HashMap *self, BufferView key, void **value) { } bool hash_map_contains(HashMap *self, BufferView key) { - return hash_map_get(self, key, NULL); + return hash_map_get_ref(self, key, NULL); } #define MIN(a, b) ((a) < (b) ? (a) : (b)) |