aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/tags.c
diff options
context:
space:
mode:
authorGravatar Austin Clements <amdragon@mit.edu>2010-12-08 19:26:05 -0500
committerGravatar Austin Clements <amdragon@mit.edu>2011-03-21 02:45:18 -0400
commitf3c1eebfaf8526129ae6946cbcd44a3c602563d6 (patch)
tree13457ad173997005f6023d274e9a0ec130bba098 /lib/tags.c
parentd9b0ae918fd9d535e819b8859eca579002146661 (diff)
Implement an internal generic string list and use it.
This replaces the guts of the filename list and tag list, making those interfaces simple iterators over the generic string list. The directory, message filename, and tags-related code now build generic string lists and then wraps them in specific iterators. The real wins come in later patches, when we use these for even more generic functionality. As a nice side-effect, this also eliminates the annoying dependency on GList in the tag list.
Diffstat (limited to 'lib/tags.c')
-rw-r--r--lib/tags.c58
1 files changed, 7 insertions, 51 deletions
diff --git a/lib/tags.c b/lib/tags.c
index 8fe4a3f0..c58924f8 100644
--- a/lib/tags.c
+++ b/lib/tags.c
@@ -20,30 +20,18 @@
#include "notmuch-private.h"
-#include <glib.h> /* GList */
-
struct _notmuch_tags {
- int sorted;
- GList *tags;
- GList *iterator;
+ notmuch_string_node_t *iterator;
};
-/* XXX: Should write some talloc-friendly list to avoid the need for
- * this. */
-static int
-_notmuch_tags_destructor (notmuch_tags_t *tags)
-{
- g_list_free (tags->tags);
-
- return 0;
-}
-
/* Create a new notmuch_tags_t object, with 'ctx' as its talloc owner.
+ * The returned iterator will talloc_steal the 'list', since the list
+ * is almost always transient.
*
* This function can return NULL in case of out-of-memory.
*/
notmuch_tags_t *
-_notmuch_tags_create (void *ctx)
+_notmuch_tags_create (const void *ctx, notmuch_string_list_t *list)
{
notmuch_tags_t *tags;
@@ -51,44 +39,12 @@ _notmuch_tags_create (void *ctx)
if (unlikely (tags == NULL))
return NULL;
- talloc_set_destructor (tags, _notmuch_tags_destructor);
-
- tags->sorted = 1;
- tags->tags = NULL;
- tags->iterator = NULL;
+ tags->iterator = list->head;
+ talloc_steal (tags, list);
return tags;
}
-/* Add a new tag to 'tags'. The tags object will create its own copy
- * of the string.
- *
- * Note: The tags object will not do anything to prevent duplicate
- * tags being stored, so the caller really shouldn't pass
- * duplicates. */
-void
-_notmuch_tags_add_tag (notmuch_tags_t *tags, const char *tag)
-{
- tags->tags = g_list_prepend (tags->tags, talloc_strdup (tags, tag));
- tags->sorted = 0;
-}
-
-/* Prepare 'tag' for iteration.
- *
- * The internal creator of 'tags' should call this function before
- * returning 'tags' to the user to call the public functions such as
- * notmuch_tags_valid, notmuch_tags_get, and
- * notmuch_tags_move_to_next. */
-void
-_notmuch_tags_prepare_iterator (notmuch_tags_t *tags)
-{
- if (! tags->sorted)
- tags->tags = g_list_sort (tags->tags, (GCompareFunc) strcmp);
- tags->sorted = 1;
-
- tags->iterator = tags->tags;
-}
-
notmuch_bool_t
notmuch_tags_valid (notmuch_tags_t *tags)
{
@@ -101,7 +57,7 @@ notmuch_tags_get (notmuch_tags_t *tags)
if (tags->iterator == NULL)
return NULL;
- return (char *) tags->iterator->data;
+ return (char *) tags->iterator->string;
}
void