Make refcounted returns move consistent.
This commit is contained in:
parent
c3f413d087
commit
df50579b5c
|
@ -38,11 +38,6 @@ struct libab_ref_trie_s {
|
||||||
* The first node in the trie.
|
* The first node in the trie.
|
||||||
*/
|
*/
|
||||||
struct libab_ref_trie_node_s* head;
|
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;
|
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.
|
* @param key the key to look under.
|
||||||
* @return a reference stored under the given key. This can be a NULL reference.
|
* @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,
|
void libab_ref_trie_get(const libab_ref_trie* trie,
|
||||||
const char* key);
|
const char* key, libab_ref* into);
|
||||||
/**
|
/**
|
||||||
* Releases the trie, decrementing the refcounts of all
|
* Releases the trie, decrementing the refcounts of all
|
||||||
* the values stored inside.
|
* the values stored inside.
|
||||||
|
|
|
@ -57,9 +57,10 @@ libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data,
|
||||||
* doesn't exist.
|
* doesn't exist.
|
||||||
* @param vec the vector to get a value from.
|
* @param vec the vector to get a value from.
|
||||||
* @param index the index to look at.
|
* @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.
|
* @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.
|
* Releases the memory allocated by the vector.
|
||||||
* The references stored in the vector have their refcount decreased.
|
* The references stored in the vector have their refcount decreased.
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
void libab_ref_trie_init(libab_ref_trie* trie) {
|
void libab_ref_trie_init(libab_ref_trie* trie) {
|
||||||
libab_ref_null(&trie->null_ref);
|
|
||||||
trie->head = NULL;
|
trie->head = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +115,8 @@ libab_result libab_ref_trie_put(libab_ref_trie* trie, const char* key,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const libab_ref* libab_ref_trie_get(const libab_ref_trie* trie,
|
void libab_ref_trie_get(const libab_ref_trie* trie,
|
||||||
const char* key) {
|
const char* key, libab_ref* into) {
|
||||||
libab_ref_trie_node* current = trie->head;
|
libab_ref_trie_node* current = trie->head;
|
||||||
while (current && *key) {
|
while (current && *key) {
|
||||||
while (current && current->key != *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;
|
current = current->child;
|
||||||
key++;
|
key++;
|
||||||
} else {
|
} 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) {
|
void libab_ref_trie_free(libab_ref_trie* trie) {
|
||||||
_libab_ref_trie_free(trie->head);
|
_libab_ref_trie_free(trie->head);
|
||||||
libab_ref_free(&trie->null_ref);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,12 @@ libab_result libab_ref_vec_insert_value(libab_ref_vec* vec, void* data,
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
const libab_ref* to_return = NULL;
|
|
||||||
if (index < vec->size) {
|
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) {
|
void libab_ref_vec_free(libab_ref_vec* vec) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user