[PATCH 2/3] lib: add support for rewinding a filenames iterator

Sascha Silbe sascha-pgp at silbe.org
Sun Jun 24 09:29:25 PDT 2012


This allows the same iterator to be traversed multiple times, instead of
destroying and reconstructing it.

Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>
---
 lib/filenames.c |   11 +++++++++++
 lib/notmuch.h   |    8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/lib/filenames.c b/lib/filenames.c
index 4f7c0d8..62ccb39 100644
--- a/lib/filenames.c
+++ b/lib/filenames.c
@@ -21,6 +21,7 @@
 #include "notmuch-private.h"
 
 struct _notmuch_filenames {
+    notmuch_string_node_t *first;
     notmuch_string_node_t *iterator;
 };
 
@@ -36,6 +37,7 @@ _notmuch_filenames_create (const void *ctx,
     if (unlikely (filenames == NULL))
 	return NULL;
 
+    filenames->first = list->head;
     filenames->iterator = list->head;
     (void) talloc_reference (filenames, list);
 
@@ -70,6 +72,15 @@ notmuch_filenames_move_to_next (notmuch_filenames_t *filenames)
 }
 
 void
+notmuch_filenames_rewind (notmuch_filenames_t *filenames)
+{
+    if (filenames == NULL)
+	return;
+
+    filenames->iterator = filenames->first;
+}
+
+void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames)
 {
     talloc_free (filenames);
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 3633bed..e99e2a3 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1382,6 +1382,14 @@ notmuch_filenames_get (notmuch_filenames_t *filenames);
 void
 notmuch_filenames_move_to_next (notmuch_filenames_t *filenames);
 
+/* Move the 'filenames' iterator back to the first filename.
+ *
+ * It is acceptable to pass NULL for 'filenames', in which case this
+ * function will do nothing.
+ */
+void
+notmuch_filenames_rewind (notmuch_filenames_t *filenames);
+
 /* Destroy a notmuch_filenames_t object.
  *
  * It's not strictly necessary to call this function. All memory from
-- 
1.7.10



More information about the notmuch mailing list