Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4B408431FBC for ; Sun, 24 Jun 2012 09:29:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Fw9Z9xeLepac for ; Sun, 24 Jun 2012 09:29:44 -0700 (PDT) Received: from smtp.chost.de (setoy.chost.de [217.160.209.225]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 3EECF431FAE for ; Sun, 24 Jun 2012 09:29:44 -0700 (PDT) Received: (qmail 14481 invoked by uid 5015); 24 Jun 2012 16:29:42 -0000 Received: (nullmailer pid 3418 invoked by uid 123); Sun, 24 Jun 2012 16:29:39 -0000 Received: from twin.sascha.silbe.org (twin.sascha.silbe.org [192.168.1.2]) by flatty.sascha.silbe.org ([192.168.1.252]) with SMTP via TCP; 24 Jun 2012 16:29:39 -0000 Received: (nullmailer pid 25949 invoked by uid 8193); Sun, 24 Jun 2012 16:29:39 -0000 From: Sascha Silbe To: notmuch Subject: [PATCH 2/3] lib: add support for rewinding a filenames iterator Date: Sun, 24 Jun 2012 18:29:25 +0200 Message-Id: <1340555366-25891-3-git-send-email-sascha-pgp@silbe.org> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1340555366-25891-1-git-send-email-sascha-pgp@silbe.org> References: <1340555366-25891-1-git-send-email-sascha-pgp@silbe.org> Mail-Followup-To: notmuch X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: Sascha Silbe List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jun 2012 16:29:45 -0000 This allows the same iterator to be traversed multiple times, instead of destroying and reconstructing it. Signed-off-by: Sascha Silbe --- 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