The previous functions were always called together, so we might as
well just have one function for this. Also, the reset() name was
poor, and prepare_iterator() is much more descriptive.
- _notmuch_tags_sort (tags);
-
- _notmuch_tags_reset (tags);
+ _notmuch_tags_prepare_iterator (tags);
_notmuch_tags_add_tag (notmuch_tags_t *tags, const char *tag);
void
_notmuch_tags_add_tag (notmuch_tags_t *tags, const char *tag);
void
-_notmuch_tags_sort (notmuch_tags_t *tags);
-
-void
-_notmuch_tags_reset (notmuch_tags_t *tags);
+_notmuch_tags_prepare_iterator (notmuch_tags_t *tags);
#include <glib.h> /* GList */
struct _notmuch_tags {
#include <glib.h> /* GList */
struct _notmuch_tags {
GList *tags;
GList *iterator;
};
GList *tags;
GList *iterator;
};
talloc_set_destructor (tags, _notmuch_tags_destructor);
talloc_set_destructor (tags, _notmuch_tags_destructor);
tags->tags = NULL;
tags->iterator = NULL;
return tags;
}
tags->tags = NULL;
tags->iterator = NULL;
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));
void
_notmuch_tags_add_tag (notmuch_tags_t *tags, const char *tag)
{
tags->tags = g_list_prepend (tags->tags, talloc_strdup (tags, tag));
+/* 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_has_more, notmuch_tags_get, and notmuch_tags_advance. */
-_notmuch_tags_sort (notmuch_tags_t *tags)
+_notmuch_tags_prepare_iterator (notmuch_tags_t *tags)
- tags->tags = g_list_sort (tags->tags, (GCompareFunc) strcmp);
-}
+ if (! tags->sorted)
+ tags->tags = g_list_sort (tags->tags, (GCompareFunc) strcmp);
+ tags->sorted = 1;
-void
-_notmuch_tags_reset (notmuch_tags_t *tags)
-{
tags->iterator = tags->tags;
}
tags->iterator = tags->tags;
}