summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/color.c3
-rw-r--r--src/trie.c8
-rw-r--r--src/trie.h5
3 files changed, 14 insertions, 2 deletions
diff --git a/src/color.c b/src/color.c
index f7a5d86..b9a788b 100644
--- a/src/color.c
+++ b/src/color.c
@@ -326,8 +326,7 @@ fail:
/** Rebuild the case-insensitive trie after all extensions have been parsed. */
static int build_iext_trie(struct colors *colors) {
- trie_destroy(&colors->iext_trie);
- trie_init(&colors->iext_trie);
+ trie_clear(&colors->iext_trie);
TRIE_FOR_EACH(&colors->ext_trie, leaf) {
size_t len = leaf->length - 1;
diff --git a/src/trie.c b/src/trie.c
index 0206509..77aa2d0 100644
--- a/src/trie.c
+++ b/src/trie.c
@@ -715,6 +715,14 @@ void trie_remove(struct trie *trie, struct trie_leaf *leaf) {
trie_remove_impl(trie, leaf);
}
+void trie_clear(struct trie *trie) {
+ trie->root = 0;
+ LIST_INIT(trie);
+
+ varena_clear(&trie->leaves);
+ varena_clear(&trie->nodes);
+}
+
void trie_destroy(struct trie *trie) {
varena_destroy(&trie->leaves);
varena_destroy(&trie->nodes);
diff --git a/src/trie.h b/src/trie.h
index 6921f62..dfaae15 100644
--- a/src/trie.h
+++ b/src/trie.h
@@ -129,6 +129,11 @@ struct trie_leaf *trie_insert_mem(struct trie *trie, const void *key, size_t len
void trie_remove(struct trie *trie, struct trie_leaf *leaf);
/**
+ * Remove all leaves from a trie.
+ */
+void trie_clear(struct trie *trie);
+
+/**
* Destroy a trie and its contents.
*/
void trie_destroy(struct trie *trie);