Add pseudo-refcounting to tree creation.

This commit is contained in:
2018-06-12 23:34:18 -07:00
parent b5b4d7816a
commit 39dd07b134
5 changed files with 28 additions and 59 deletions

View File

@@ -47,10 +47,23 @@ int _tree_foreach_free(void* data, va_list args) {
return 0;
}
void libab_tree_free_recursive(libab_tree* tree) {
if (libab_tree_has_vector(tree->variant)) {
vec_foreach(&tree->children, NULL, compare_always, _tree_foreach_free);
}
libab_tree_free(tree);
free(tree);
int _tree_needs_free(libab_tree* tree) {
return ((tree->variant == TREE_FUN && --tree->int_value) | (tree->variant != TREE_FUN));
}
void libab_tree_free_recursive(libab_tree* tree) {
if(_tree_needs_free(tree)) {
if (libab_tree_has_vector(tree->variant)) {
vec_foreach(&tree->children, NULL, compare_always, _tree_foreach_free);
}
libab_tree_free(tree);
free(tree);
}
}
void libab_tree_refcount_free(libab_tree* tree) {
if(_tree_needs_free(tree)) {
libab_tree_free(tree);
free(tree);
}
}