]> git.notmuchmail.org Git - notmuch/blobdiff - lib/directory.cc
Add a generic function to get a list of terms with some prefix.
[notmuch] / lib / directory.cc
index 946be4f45ef0704ea50041a45c4a20a0d6e48c95..70e1693ea54eaa4f3bfe5e5312610318d803621f 100644 (file)
 
 /* Create an iterator to iterate over the basenames of files (or
  * directories) that all share a common parent directory.
- *
- * The code here is general enough to be reused for any case of
- * iterating over the non-prefixed portion of terms sharing a common
- * prefix.
  */
 static notmuch_filenames_t *
 _create_filenames_for_terms_with_prefix (void *ctx,
                                         notmuch_database_t *notmuch,
                                         const char *prefix)
 {
-    notmuch_filename_list_t *filename_list;
+    notmuch_string_list_t *filename_list;
     Xapian::TermIterator i, end;
-    int prefix_len = strlen (prefix);
 
-    filename_list = _notmuch_filename_list_create (ctx);
+    i = notmuch->xapian_db->allterms_begin();
+    end = notmuch->xapian_db->allterms_end();
+    filename_list = _notmuch_database_get_terms_with_prefix (ctx, i, end,
+                                                            prefix);
     if (unlikely (filename_list == NULL))
        return NULL;
 
-    end = notmuch->xapian_db->allterms_end (prefix);
-
-    for (i = notmuch->xapian_db->allterms_begin (prefix); i != end; i++)
-    {
-       std::string term = *i;
-
-       _notmuch_filename_list_add_filename (filename_list, term.c_str () +
-                                            prefix_len);
-    }
-
     return _notmuch_filenames_create (ctx, filename_list);
 }