]> granicus.if.org Git - mutt/commitdiff
Change maildir and mh check_mailbox to use dynamic sized hash. (closes #3973)
authorKevin McCarthy <kevin@8t8.us>
Tue, 26 Sep 2017 01:40:32 +0000 (18:40 -0700)
committerKevin McCarthy <kevin@8t8.us>
Tue, 26 Sep 2017 01:40:32 +0000 (18:40 -0700)
The original patch is by Matt Fleming, originally posted at
http://www.codeblueprint.co.uk/2017/01/15/a-kernel-devs-approach-to-improving2

The comments there indicate Matt tried to submit to trac and mutt-dev,
but ran into registration problems.  Thank you for the patch, and
sorry for those problems, Matt.

I modified the patch by making the same change to the
mh_check_mailbox() code too.

mh.c

diff --git a/mh.c b/mh.c
index 060368e997621a47545f9b703e96f5660ae94527..2618fe12f121f1a94c0167829485001ba359a664 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -2095,6 +2095,7 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint)
   struct maildir *md;          /* list of messages in the mailbox */
   struct maildir **last, *p;
   int i;
+  int count = 0;
   HASH *fnames;                        /* hash table for quickly looking up the base filename
                                   for a maildir message */
   struct mh_data *data = mh_data (ctx);
@@ -2132,15 +2133,15 @@ static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint)
   md = NULL;
   last = &md;
   if (changed & 1)
-    maildir_parse_dir (ctx, &last, "new", NULL, NULL);
+    maildir_parse_dir (ctx, &last, "new", &count, NULL);
   if (changed & 2)
-    maildir_parse_dir (ctx, &last, "cur", NULL, NULL);
+    maildir_parse_dir (ctx, &last, "cur", &count, NULL);
 
   /* we create a hash table keyed off the canonical (sans flags) filename
    * of each message we scanned.  This is used in the loop over the
    * existing messages below to do some correlation.
    */
-  fnames = hash_create (1031, 0);
+  fnames = hash_create (count, 0);
 
   for (p = md; p; p = p->next)
   {
@@ -2248,6 +2249,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint)
   struct maildir *md, *p;
   struct maildir **last = NULL;
   struct mh_sequences mhs;
+  int count = 0;
   HASH *fnames;
   int i;
   struct mh_data *data = mh_data (ctx);
@@ -2292,7 +2294,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint)
   md   = NULL;
   last = &md;
 
-  maildir_parse_dir (ctx, &last, NULL, NULL, NULL);
+  maildir_parse_dir (ctx, &last, NULL, &count, NULL);
   maildir_delayed_parsing (ctx, &md, NULL);
 
   if (mh_read_sequences (&mhs, ctx->path) < 0)
@@ -2301,7 +2303,7 @@ static int mh_check_mailbox (CONTEXT * ctx, int *index_hint)
   mhs_free_sequences (&mhs);
 
   /* check for modifications and adjust flags */
-  fnames = hash_create (1031, 0);
+  fnames = hash_create (count, 0);
 
   for (p = md; p; p = p->next)
   {