X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=tags.c;h=afc132c50e17c2f41cb6f6709e3c6d827d237b95;hp=36f3fa40cb135a7804f45513fab952de53d9c5ec;hb=c6aae1561a51ba12f716d25e3731019d16115ab4;hpb=3dce2007887717ec4ec0a1e815591c957acd1ba1 diff --git a/tags.c b/tags.c index 36f3fa40..afc132c5 100644 --- a/tags.c +++ b/tags.c @@ -23,6 +23,7 @@ #include /* GList */ struct _notmuch_tags { + int sorted; GList *tags; GList *iterator; }; @@ -52,27 +53,38 @@ _notmuch_tags_create (void *ctx) talloc_set_destructor (tags, _notmuch_tags_destructor); + tags->sorted = 1; 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)); + 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_has_more, notmuch_tags_get, and notmuch_tags_advance. */ void -_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; }