diff options
Diffstat (limited to 'src/std')
-rw-r--r-- | src/std/buffer.c | 6 | ||||
-rw-r--r-- | src/std/hash_map.c | 9 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/std/buffer.c b/src/std/buffer.c index e311c8f..dd7d0f6 100644 --- a/src/std/buffer.c +++ b/src/std/buffer.c @@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> void tsl_buffer_init(TslBuffer *self) { self->data = NULL; @@ -44,6 +45,11 @@ int tsl_buffer_append(TslBuffer *self, const void *data, size_t size) { return 1; } +void tsl_buffer_pop(TslBuffer *self, size_t size) { + assert(self->size >= size); + self->size -= size; +} + void* tsl_buffer_begin(TslBuffer *self) { return self->data; } diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 968a5ea..7ba1daf 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -43,10 +43,6 @@ void tsl_hash_map_deinit(TslHashMap *self) { /* TODO: Remove if (data) and if (output) */ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, const TslStringView *key, size_t size, const void *data, void **output) { TslHashMapNode *next_node; - /* - TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert - method and use that directly. - */ uint8_t *node_data = malloc(sizeof(hash) + sizeof(key->size) + key->size + sizeof(size) + size); if(output) *output = node_data; @@ -65,8 +61,13 @@ static int tsl_hash_map_append_bucket(TslHashMapNode **head_node, uint64_t hash, } memcpy(node_data, &hash, sizeof(hash)); + /* TODO: Instead of allocating space for the key, use the key data pointer and size directly. */ memcpy(node_data + sizeof(hash), &key->size, sizeof(key->size)); memcpy(node_data + sizeof(hash) + sizeof(key->size), key->data, key->size); + /* + TODO: Instead of allocating space for the data, allow the user to pass a pointer in the insert + method and use that directly. + */ memcpy(node_data + sizeof(hash) + sizeof(key->size) + key->size, &size, sizeof(size)); if(data) memcpy(node_data + sizeof(hash) + sizeof(key->size) + key->size + sizeof(size), data, size); |