diff --git a/include/ref_trie.h b/include/ref_trie.h index fea6128..71b0398 100644 --- a/include/ref_trie.h +++ b/include/ref_trie.h @@ -38,11 +38,6 @@ struct libab_ref_trie_s { * The first node in the trie. */ struct libab_ref_trie_node_s* head; - /** - * Reference (initialized to NULL) returned - * if no key is found. - */ - libab_ref null_ref; }; typedef struct libab_ref_trie_node_s libab_ref_trie_node; @@ -78,8 +73,8 @@ libab_result libab_ref_trie_put(libab_ref_trie* trie, const char* key, * @param key the key to look under. * @return a reference stored under the given key. This can be a NULL reference. */ -const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie, - const char* key); +void libab_ref_trie_get(const libab_ref_trie* trie, + const char* key, libab_ref* into); /** * Releases the trie, decrementing the refcounts of all * the values stored inside. diff --git a/include/ref_vec.h b/include/ref_vec.h index 8da62b9..e81f265 100644 --- a/include/ref_vec.h +++ b/include/ref_vec.h @@ -57,9 +57,10 @@ libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data, * doesn't exist. * @param vec the vector to get a value from. * @param index the index to look at. + * @param into the reference to store the result value into. * @return the reference stored at the given index. */ -const libab_ref* libab_ref_vec_index(libab_ref_vec* vec, size_t index); +void libab_ref_vec_index(libab_ref_vec* vec, size_t index, libab_ref* into); /** * Releases the memory allocated by the vector. * The references stored in the vector have their refcount decreased. diff --git a/src/ref_trie.c b/src/ref_trie.c index 72d3b28..a9faab5 100644 --- a/src/ref_trie.c +++ b/src/ref_trie.c @@ -2,7 +2,6 @@ #include void libab_ref_trie_init(libab_ref_trie* trie) { - libab_ref_null(&trie->null_ref); trie->head = NULL; } @@ -116,8 +115,8 @@ libab_result libab_ref_trie_put(libab_ref_trie* trie, const char* key, return result; } -const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie, - const char* key) { +void libab_ref_trie_get(const libab_ref_trie* trie, + const char* key, libab_ref* into) { libab_ref_trie_node* current = trie->head; while (current && *key) { while (current && current->key != *key) { @@ -130,13 +129,13 @@ const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie, current = current->child; key++; } else { - return ¤t->ref; + libab_ref_copy(¤t->ref, into); + return; } } - return &trie->null_ref; + libab_ref_null(into); } void libab_ref_trie_free(libab_ref_trie* trie) { _libab_ref_trie_free(trie->head); - libab_ref_free(&trie->null_ref); } diff --git a/src/ref_vec.c b/src/ref_vec.c index 6867ff5..65a19d7 100644 --- a/src/ref_vec.c +++ b/src/ref_vec.c @@ -50,12 +50,12 @@ libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data, return result; } -const libab_ref* libab_ref_vec_index(libab_ref_vec* vec, size_t index) { - const libab_ref* to_return = NULL; +void libab_ref_vec_index(libab_ref_vec* vec, size_t index, libab_ref* into) { if (index < vec->size) { - to_return = &vec->data[index]; + libab_ref_copy(&vec->data[index], into); + } else { + libab_ref_null(into); } - return to_return; } void libab_ref_vec_free(libab_ref_vec* vec) {