From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 6F4306DE0282 for ; Sun, 26 Aug 2018 18:54:11 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.001 X-Spam-Level: X-Spam-Status: No, score=0.001 tagged_above=-999 required=5 tests=[AWL=0.012, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uz7TiWs_rLLh for ; Sun, 26 Aug 2018 18:54:10 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id 23CB16DE0273 for ; Sun, 26 Aug 2018 18:54:10 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.89) (envelope-from ) id 1fu6jG-0002Sj-18; Sun, 26 Aug 2018 21:54:06 -0400 Received: (nullmailer pid 23715 invoked by uid 1000); Mon, 27 Aug 2018 01:54:04 -0000 From: David Bremner To: Gregor Zattler , notmuch@notmuchmail.org Subject: [PATCH] WIP: sort top level messages in thread Date: Sun, 26 Aug 2018 22:53:53 -0300 Message-Id: <20180827015353.23652-1-david@tethera.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <87va8unnor.fsf@len.workgroup> References: <87va8unnor.fsf@len.workgroup> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Aug 2018 01:54:11 -0000 this needs a test, and memory de-allocation of the replaced lists. Currently it creates a fair amount of garbage. --- Hi Gregor; Sorry for the lack of reply, some vacation intervened. Can you test this patch? I think it fixes the second thread also. lib/message.cc | 43 +++++++++++++++++++++++-------------------- lib/notmuch-private.h | 5 +++-- lib/thread.cc | 9 ++------- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 3c547298..f329be20 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -639,34 +639,37 @@ _cmpmsg (const void *pa, const void *pb) return (int) difftime (time_a, time_b); } -void -_notmuch_message_sort_subtree (notmuch_message_t *root) -{ - size_t child_count = 0; - size_t child_capacity = 16; - notmuch_message_t **children = talloc_zero_array (root, notmuch_message_t *, child_capacity); +notmuch_message_list_t * +_notmuch_message_sort_subtrees (notmuch_message_list_t *list) { + + size_t count = 0; + size_t capacity = 16; - for (notmuch_messages_t *messages = _notmuch_messages_create (root->replies); + if (!list) + return list; + + notmuch_message_t **message_array = talloc_zero_array (list, notmuch_message_t *, capacity); + + for (notmuch_messages_t *messages = _notmuch_messages_create (list); notmuch_messages_valid (messages); notmuch_messages_move_to_next (messages)) { - notmuch_message_t *child = notmuch_messages_get (messages); - if (child_count >= child_capacity) { - child_capacity *= 2; - children = talloc_realloc (root, children, notmuch_message_t *, child_capacity); + notmuch_message_t *root = notmuch_messages_get (messages); + if (count >= capacity) { + capacity *= 2; + message_array = talloc_realloc (root, message_array, notmuch_message_t *, capacity); } - children[child_count++] = child; - _notmuch_message_sort_subtree (child); + message_array[count++] = root; + root->replies = _notmuch_message_sort_subtrees (root->replies); } - notmuch_message_list_t *new_replies = _notmuch_message_list_create (root); + notmuch_message_list_t *new_list = _notmuch_message_list_create (list); - qsort (children, child_count, sizeof (notmuch_message_t *), _cmpmsg); - for (size_t i=0; ireplies); - root->replies = new_replies; - talloc_free (children); + talloc_free (message_array); + return new_list; } notmuch_messages_t * diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 67fd4990..64f4e982 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -558,8 +558,9 @@ size_t _notmuch_message_get_thread_depth (notmuch_message_t *message); void _notmuch_message_label_depths (notmuch_message_t *message, size_t depth); -void -_notmuch_message_sort_subtree (notmuch_message_t *message); + +notmuch_message_list_t * +_notmuch_message_sort_subtrees (notmuch_message_list_t *list); /* sha1.c */ diff --git a/lib/thread.cc b/lib/thread.cc index a5047103..e9e15a5c 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -505,13 +505,8 @@ _resolve_thread_relationships (notmuch_thread_t *thread) _notmuch_message_list_add_message (thread->toplevel_list, message); } - for (notmuch_messages_t *messages = _notmuch_messages_create (thread->toplevel_list); - notmuch_messages_valid (messages); - notmuch_messages_move_to_next (messages)) - { - notmuch_message_t *message = notmuch_messages_get (messages); - _notmuch_message_sort_subtree (message); - } + /* XXX this creates garbage */ + thread->toplevel_list = _notmuch_message_sort_subtrees (thread->toplevel_list); talloc_free (local); } -- 2.18.0