diff options
author | Carl Worth <cworth@cworth.org> | 2009-10-26 14:12:56 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2009-10-26 14:12:56 -0700 |
commit | ef3ab5781a3730e019f92517366029540a960cd0 (patch) | |
tree | bb40ef980076be11f72bc05562026abb5dee6562 | |
parent | 1726c5c814aecd924849a0b91c82d420af945827 (diff) |
tags: Replace sort() and reset() with prepare_iterator().
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.
-rw-r--r-- | message.cc | 4 | ||||
-rw-r--r-- | notmuch-private.h | 5 | ||||
-rw-r--r-- | tags.c | 24 |
3 files changed, 20 insertions, 13 deletions
@@ -318,9 +318,7 @@ notmuch_message_get_tags (notmuch_message_t *message) i++; } - _notmuch_tags_sort (tags); - - _notmuch_tags_reset (tags); + _notmuch_tags_prepare_iterator (tags); return tags; } diff --git a/notmuch-private.h b/notmuch-private.h index 3d2610a..c6d8e35 100644 --- a/notmuch-private.h +++ b/notmuch-private.h @@ -283,10 +283,7 @@ 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); NOTMUCH_END_DECLS @@ -23,6 +23,7 @@ #include <glib.h> /* 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; } |